Search code examples
linuxnetworkingscapy

How to generate packets with incrementing lengths with scapy


I need to send a sequence of packets from min to max ethernet size to verify hardware. Would be best to use scapy since that's the tool of choice for existing tests.

Is there a way to have scapy to send a sequence of packets of incrementing length?

Using the [x,y] form for length seems to only change header field values, not data length.

pak=(Ether()/IP(len=[100,101])

It is possible to create a large pcap file with all the required packets and read from that, but I was hoping for something more lightweight.


Solution

  • You could do something like

    packets = (Ether()/IP()/Raw(load=b"\x00" * i) for i in range(1000))
    sendp(packets)
    

    to send packets with a payload from 0 to 1000. The lengths will be computed automatically