Search code examples
pythonpython-3.xpcaplibpcappacket-capture

Pylibpcap for python-3.x


There was a library pylibpcap for python2 that contained the functionality to create pcap objects like this:

import pcap

pc = pcap.pcapObject()

Now I'm looking for an analogue for python3, but from what I found (pypcap, pcap-ct), these libraries don't contain similar functionality and look completely different. So maybe someone knows how the pylibpcap library can be replaced in python3? I will be grateful for any advice.


Solution

  • You can use this package similar to your requirement, installation steps mentioned below:

    $ sudo apt-get install libpcap-dev
    $ pip3 install Cython python-libpcap
    

    And usage as below:

    from pylibpcap import OpenPcap
    p = OpenPcap("pcap.pcap", "a")
    p.write(buf)