Background:
I'm using scapy to test a network device that can selectively loop-back packets by swapping source/dest MACs, IP addresses, and layer 4 port numbers. Swapping can be selected for layer_2_only
, layers_2_and_3
, layers_2_3_and_4
. I'm running scapy on a server, transmitting packets to the device and validating that the packets sent back have the appropriate source/dest fields swapped depending on the setting.
Problem:
The scapy srploop()
method, which sends packets and receives matches works well for message types like PING and ARP. I'm finding that if I transmit a UDP packet and the source/dest ports are not reversed by the loop-back device, then scapy doesn't treat the looped-back packet like a match. When the port numbers are reversed by the loop-back device, the packets are detected as matches.
Questions:
Is there a way to override or otherwise influence scapy's packet matching logic? For example, being able to disable matching at layer 4 would be useful. I've looked at the documentation and haven't come across anything that suggests that this is possible.
Is there another way to achieve this in scapy. I've experimented with using
send()
followed bysniff()
but I haven't been successful at capturing the replies using that method.