Pylibpcap for python-3.x

Viewed 590

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.

2 Answers

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)

You can store pcap files in python using scapy module. install it by -

pip install scapy

You can store the network traffic in pcap files using scapy. More info at this link - creating a pcap file using python

Related