This is how I take the packet size / length when sniffing packets using scapy.
pkt.sprintf("%IP.len%")
Full example:
from scapy.all import * # callback function - called for every packet def traffic_monitor_callbak(pkt): if IP in pkt: print pkt.sprintf("%IP.len%") # capture traffic for 10 seconds sniff(iface="eth1", prn=traffic_monitor_callbak, store=0, timeout=10)
I used scapy to sniff packages, so I'm not sure if this makes sense when using scapy for other things like creating packages.
source share