Search code examples
scapypacket-sniffers

Sniffing packets on localhost with Scapy


I'm learning how to use scapy to sniff packets. I have set up a simple echo server running on localhost on port 50420.

I then enter the following line in my terminal to sniff for packets on that port when I send traffic over it:

p = sniff(filter = 'port 50420')

However, no packets are captured, although the data flowed correctly. I have verified that sniffing works for other traffic not using localhost. How can I sniff this localhost traffic using Scapy, if at all possible?


Solution

  • With that line you are sniffing the traffic over the port 50420, but you should do something more. You should add one function to jump when you sniff the packets

    sniff(filter="port 50420",prn=myFunction)
    

    And write myFunction:

    def myFunction(pkt):
        print "Packet!"