Pypcap

Python/C bindings for the libpcap library

View the Project on GitHub kbandla/pypcap

pypcap

Python/C bindings for the libpcap library. Most of the functions are 1:1 mapped to the libpcap library.

Example 1

>>> import pypcap
>>> pypcap.pcap_lookupdev()
'fw0'
>>> pypcap.pcap_findalldevs()
['fw0', 'en0', 'utun0', 'en1', 'p2p0']
>>> pypcap.pcap_lookupnet('en1')
('192.168.1.10', '255.255.252.0')
>>> pypcap.pcap_lib_version()
'libpcap version 1.1.1'

Example 2

from pypcap import pcap
import dpkt
x = pcap()
x.pcap_create( 'eth0' )
x.pcap_set_promisc( True )
x.pcap_activate()
x.pcap_compile( 'udp' )

def pcap_callback(pkt):
    # do stuff with packet
    eth = dpkt.ethernet.Ethernet(pkt)

x.pcap_set_callback(pcap_callback)
x.pcap_loop()

Notes

Linux

Research

Remaining Work

License

See LICENSE file

Requires

Tested on