Cython libpcap
Project description
Cython libpcap
Documentation: https://python-libpcap.readthedocs.io
Features
Read pcap file
Write pcap file
Merge pcap file
Get first iface
Capture data
Installation
To install python-libpcap, run this command in your terminal:
$ sudo apt-get install libpcap-dev
$ pip install python-libpcap
Demo
Console:
$ mpcap -i pcap/ -o pcap.pcap port 502
$ sudo capture -i enp2s0 -v
Read pcap:
from pylibpcap.pcap import rpcap
for len, t, pkt in rpcap("tests/dns.pcap"):
print("Buf length:", len)
print("Time:", t)
print("Buf:", pkt)
Write pcap:
from pylibpcap.pcap import wpcap
buf = b'\x00\xc0\x9f2A\x8c\x00\xe0\x18\xb1\x0c\xad\x08\x00E\x00\x008' \
b'\x00\x00@\x00@\x11eG\xc0\xa8\xaa\x08\xc0\xa8\xaa\x14\x80\x1b' \
b'\x005\x00$\x85\xed\x102\x01\x00\x00\x01\x00\x00\x00\x00\x00' \
b'\x00\x06google\x03com\x00\x00\x10\x00\x01'
wpcap(buf, "pcap.pcap")
wpcap([buf, buf], "pcap.pcap)
Merge pcap:
from pylibpcap.pcap import mpcap
mpcap("demo.pcap", "demo2.pcap")
mpcap("pcap/", "output.pcap", "port 502")
Get first iface:
from pylibpcap.pcap import get_first_iface
print(get_first_iface())
Capture data:
from pylibpcap.pcap import sniff
for plen, t, buf in sniff("enp2s0", filters="port 53", count=3, promisc=1, out_file="pcap.pcap"):
print("[+]: Payload len=", plen)
print("[+]: Time", t)
print("[+]: Payload", buf)
Credits
This package was created with Cookiecutter and the caizhengxin/cookiecutter-package project template.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-libpcap-0.1.2.tar.gz
(60.4 kB
view details)
File details
Details for the file python-libpcap-0.1.2.tar.gz
.
File metadata
- Download URL: python-libpcap-0.1.2.tar.gz
- Upload date:
- Size: 60.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d2424d43c735e3c9c0a6a563d086ad6f7b7ddc51b95299e5c9f344cca004b460 |
|
MD5 | 2c9ad482599d1ef2e0e5e2184ff5931e |
|
BLAKE2b-256 | 04ba035fbea47f9e822de756176c7708a10b4f22b2c7d2bce80720fcc03bb00e |