4
votes

I've been following Seitz's black hat python book and he gives an example of capturing network traffic using the scapy library.

import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *

def packet_callback(packet):
    print packet.show()

sniff(filter="",iface="any",prn=packet_callback, count = 1)

I run the above function as follows: sudo python sniffer.py and open google chrome to a page. No packets get captured. I do a ping request to a domain and nothing gets captured. I was expecting the print packet.show() line to print the first packet being sent.

All of this is being run on a Macbook Pro on a wireless internet connection.

Can someone help me troubleshoot?

2

2 Answers

3
votes

if you want scapy to sniff on all interfaces, just remove the iface = "any" parameter. Since "any" is not an interface therefore scapy cannot sniff.

Also remove the filter parameter since it is not applying any filter. The correct command would like like this.

sniff(prn=packet_callback, count = 1)
1
votes

iface argument expects exact name of the interface. Most likely you do not have an interface named ANY. You can omit the argument, which is most likely what you have to do in this case, or use actual interface name (such as "eth0").

I actually get an exception "No such device", when I try your code. Is this the actual code you run?

Also, please, write scapy version. I am using python3 version, which you can get from http://github.com/phaethon/scapy or as scapy-python3.