Skip to main content

Python binding for the libpcap C library.

Project description

libpcap

Python binding for the libpcap C library.

Overview

Python libpcap module is a low-level binding for libpcap C library.
It is an effort to allow python programs full access to the API provided by the well known libpcap Unix C library and by its implementations provided under Win32 systems by such packet capture systems as: Npcap, WinPcap

PyPI record.

Documentation.

libpcap is a lightweight Python package, based on the ctypes library.
It is fully compliant implementation of the original C libpcap from 1.0.0 up to 1.9.0 API and the WinPcap’s 4.1.3 libpcap (1.0.0rel0b) API by implementing whole its functionality in a clean Python instead of C.

Useful libpcap API documentation can be found at:

libpcap uses the underlying libpcap C shared library as specified in libpcap.cfg (system’s libpcap shared library is the default), but there is also ability to specify it programmatically by one of the following ways:

import libpcap
libpcap.config(LIBPCAP=None)       # system's libpcap library will be used
# or
libpcap.config(LIBPCAP="npcap")
# or
libpcap.config(LIBPCAP="wpcap")    # included wpcap library will be used
# or
libpcap.config(LIBPCAP="tcpdump")  # included tcpdump library will be used
# or                               # (currently works only for Linux x64)
libpcap.config(LIBPCAP="libpcap shared library absolute path")

About original libpcap:

LIBPCAP 1.x.y by “The Tcpdump Group”:

https://www.tcpdump.org

Anonymous Git is available via:

git clone https://github.com/the-tcpdump-group/libpcap.git

formerly from:

Lawrence Berkeley National Laboratory
Network Research Group <libpcap@ee.lbl.gov>

This directory contains source code for libpcap, a system-independent interface for user-level packet capture. libpcap provides a portable framework for low-level network monitoring. Applications include network statistics collection, security monitoring, network debugging, etc. Since almost every system vendor provides a different interface for packet capture, and since we’ve developed several tools that require this functionality, we’ve created this system-independent API to ease in porting and to alleviate the need for several system-dependent packet capture modules in each application.

Support for particular platforms and BPF:

For some platforms there are README.{system} files that discuss issues with the OS’s interface for packet capture on those platforms, such as how to enable support for that interface in the OS, if it’s not built in by default.

The libpcap interface supports a filtering mechanism based on the architecture in the BSD packet filter. BPF is described in the 1993 Winter Usenix paper “The BSD Packet Filter: A New Architecture for User-level Packet Capture” (compressed PostScript, gzipped PostScript, PDF).

Although most packet capture interfaces support in-kernel filtering, libpcap utilizes in-kernel filtering only for the BPF interface. On systems that don’t have BPF, all packets are read into user-space and the BPF filters are evaluated in the libpcap library, incurring added overhead (especially, for selective filters). Ideally, libpcap would translate BPF filters into a filter program that is compatible with the underlying kernel subsystem, but this is not yet implemented.

BPF is standard in 4.4BSD, BSD/OS, NetBSD, FreeBSD, OpenBSD, DragonFly BSD, and macOS; an older, modified and undocumented version is standard in AIX. DEC OSF/1, Digital UNIX, Tru64 UNIX uses the packetfilter interface but has been extended to accept BPF filters (which libpcap utilizes). Also, you can add BPF filter support to Ultrix using the kernel source and/or object patches.

Linux has a number of BPF based systems, and libpcap does not support any of the eBPF mechanisms as yet, although it supports many of the memory mapped receive mechanisms. See the Linux-specific README, for more information.

Note to Linux distributions and *BSD systems that include libpcap:

There’s now a rule to make a shared library, which should work on Linux and *BSD, among other platforms.

It sets the soname of the library to “libpcap.so.1”; this is what it should be, NOT “libpcap.so.1.x” or “libpcap.so.1.x.y” or something such as that.

We’ve been maintaining binary compatibility between libpcap releases for quite a while; there’s no reason to tie a binary linked with libpcap to a particular release of libpcap.

Requirements

  • It is a fully independent package.
    All necessary things are installed during the normal installation process.
  • ATTENTION: currently works and tested only for Windows.

Installation

Prerequisites:

To install run:

python -m pip install --upgrade libpcap

Development

Prerequisites:

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

    python -m pip install --upgrade nox

Visit Development page.

Installation from sources:

clone the sources:

git clone https://github.com/karpierz/libpcap libpcap

and run:

python -m pip install ./libpcap

or on development mode:

python -m pip install --editable ./libpcap

License

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

Authors

Sponsoring

If you would like to sponsor the development of this project, your contribution is greatly appreciated.
As I am now retired, any support helps me dedicate more time to maintaining and improving this work.

Donate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

libpcap-1.11.0b28.tar.gz (6.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

libpcap-1.11.0b28-py3-none-any.whl (6.3 MB view details)

Uploaded Python 3

File details

Details for the file libpcap-1.11.0b28.tar.gz.

File metadata

  • Download URL: libpcap-1.11.0b28.tar.gz
  • Upload date:
  • Size: 6.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for libpcap-1.11.0b28.tar.gz
Algorithm Hash digest
SHA256 0ecd3f97fc8a5c4279ccf2bf52c40ea0318bf6c8aae94e6fa540e6aa320312c6
MD5 a036d63ad950a3a8d439ea34be1d3f2c
BLAKE2b-256 f1a5848134cbbdae8c308f21370b746854eb7443532cf900a6132804fb2afe81

See more details on using hashes here.

File details

Details for the file libpcap-1.11.0b28-py3-none-any.whl.

File metadata

  • Download URL: libpcap-1.11.0b28-py3-none-any.whl
  • Upload date:
  • Size: 6.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for libpcap-1.11.0b28-py3-none-any.whl
Algorithm Hash digest
SHA256 c8caf2ae683e46541d78248d247a5ac7bd5e227fc8e68703fd801cfe1830e379
MD5 e77b1f0320fca0966a024aa4764187da
BLAKE2b-256 15c4b248dcd542edda1b0f75b6e51053886e9440a80f03d362a74fc9eb57b656

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page