I am using Scapy to capture packets by using the following code
from scapy.all import *
def verify(p):
p.display()
sniff(prn=verify, iface="lo")
The sniff function captures every packet multiple times. For example, if I have a DNS query packet, this packet will display two times. How can make The sniff function to capture each packet only single time?
This is expected behavior. Scapy sees the packets on the loopback interface both when they "leave" and when they "arrive." So everything is duplicated with no distinction, because loopback is a special interface. Perhaps you should yourself just skip every second packet.
It was reported as a bug once, but rejected: https://bitbucket.org/secdev/scapy/issues/887/sniff-sends-packets-twice
来源:https://stackoverflow.com/questions/52232080/scapy-sniff-the-packet-multiple-times