Search code examples
pythonpython-3.xnetwork-programmingscapy

Capturing packets in python 3


How can I capture packets with python3? I would like to emphasize that my goal is not to listen to traffic, but to capture it. For instance, the Python Scapy module has a sniff function that allows you to listen to the traffic, but not to capture it. Is there a function that allows me to capture a packet so that I can determine whether to send it or not?


Solution

  • To capture traffic you just save what you sniffed.

    from scapy.all import *
    wrpcap("somefile.pcap", sniff(iface='yourInterface', count=100))