pcap-ct documentation

pcap-ct

Python wrapper for the pcap library.

Overview

Python pcap-ct package is a simplified object-oriented Python wrapper for libpcap C library - the current tcpdump.org version, and the WinPcap port for Windows..

pcap-ct is a pure Python package, based on the low-level libcap package.
It is fully compliant implementation of the original PyPCAP 1.2.3 API (with some minor improvements and bug fixes) by implementing whole its functionality in a clean Python instead of Cython and C.

PyPI record.

Documentation.

About original PyPCAP:

Borrowed from the original website:

PyPCAP

This is a simplified object-oriented Python wrapper for libpcap - the current tcpdump.org version, and the WinPcap port for Windows.

Example use #1:

>>> import pcap
>>> sniffer = pcap.pcap(name=None, promisc=True, immediate=True, timeout_ms=50)
>>> addr = lambda pkt, offset: '.'.join(str(ord(pkt[i])) for i in range(offset, offset + 4))
>>> for ts, pkt in sniffer:
...     print('%d\tSRC %-16s\tDST %-16s' % (ts, addr(pkt, sniffer.dloff + 12), addr(pkt, sniffer.dloff + 16)))
...

Example use #2:

Listing Interfaces

>>> import pcap
>>> print ("Interfaces:\n" + '\n'.join(pcap.findalldevs()))

Windows notes

WinPcap has compatibility issues with Windows 10, therefore it’s recommended to use Npcap (Nmap’s packet sniffing library for Windows, based on the WinPcap/Libpcap libraries, but with improved speed, portability, security, and efficiency). Please enable WinPcap API-compatible mode during the library installation.

Installation

Prerequisites:

To install run:

python -m pip install --upgrade pcap-ct

Development

Prerequisites:

  • Development is strictly based on tox. To install it run:

    python -m pip install --upgrade tox
    

Visit development page.

Installation from sources:

clone the sources:

and run:

python -m pip install ./pcap-ct

or on development mode:

python -m pip install --editable ./pcap-ct

License

Copyright (c) 2016-2022, Adam Karpierz
Licensed under the BSD license
Please refer to the accompanying LICENSE file.

Authors

Contents

Indices and tables