libpnet-pyo3
pyo3 bindings for libpnet.
Status: alpha. Wheels published for Linux + macOS in v0.1. libpnet itself supports Windows (via Npcap or winpkfilter); the Windows wheel build for this wrapper is planned for a later release.
Install
pip install libpnet-pyo3
Wheels published for Linux (x86_64, aarch64) and macOS (x86_64, aarch64), Python 3.10+ (abi3).
Raw sockets need elevated privilege:
- Linux:
sudoor grantCAP_NET_RAWto the Python interpreter - macOS:
sudo(BPF and raw sockets are root-only)
Quick start
from libpnet_pyo3 import tcp_sr1, icmp_ping, sniff, arp_who_has
# TCP SYN probe
resp = tcp_sr1(dst="1.2.3.4", dport=80, flags="S", timeout=1.0)
if resp and resp.is_synack():
print(f"open, ttl={resp.ttl}, window={resp.window}")
# Ping
echo = icmp_ping("1.1.1.1", timeout=1.0)
if echo and echo.is_echo_reply():
print(f"reply from {echo.src} ttl={echo.ttl}")
# ARP
reply = arp_who_has("192.168.1.1")
if reply:
print(f"{reply.ip} is at {reply.mac}")
# Sniff
for pkt in sniff(count=10, timeout=5.0):
print(pkt)
API
Send-and-receive
| Function | Returns |
|---|---|
tcp_sr1(dst, dport, flags="S", *, sport=None, src=None, seq=None, window=64240, ttl=64, payload=None, timeout=1.0) |
TcpResponse | None |
udp_sr1(dst, dport, payload, *, sport=None, src=None, ttl=64, timeout=1.0) |
UdpResponse | None |
icmp_ping(dst, *, src=None, ident=None, seq=1, ttl=64, payload=None, timeout=1.0) |
IcmpResponse | None |
arp_who_has(target_ip, *, iface=None, timeout=1.0) |
ArpReply | None |
Send-only
| Function | |
|---|---|
tcp_send(dst, dport, flags="S", ...) |
fire-and-forget TCP |
udp_send(dst, dport, payload, ...) |
fire-and-forget UDP |
send_ipv4_bytes(dst, packet, *, protocol="tcp") |
send pre-built IPv4 bytes |
send_l2_bytes(packet, *, iface=None) |
send pre-built Ethernet frame |
Capture
sniff(*, iface=None, count=None, timeout=None) -> list[SniffedPacket] — at least one of count/timeout is required.
Packet builders (return raw bytes)
build_tcp_packet, build_udp_packet, build_icmp_echo, build_arp_request — same kwargs as the send-receive equivalents.
Helpers
| Function | |
|---|---|
list_interfaces() |
list[Interface] — name/mac/ipv4/ipv6/is_up/is_loopback/index |
default_interface() |
first up, non-loopback iface with an IPv4 |
interface_for(name) |
look up by name |
source_ipv4_for(dst) |
source IPv4 the kernel would pick for dst |
Response objects
TcpResponse:src dst sport dport flags seq ack window ttl payload, methodshas_flag(f),is_synack(),is_rst()UdpResponse:src dst sport dport ttl payloadIcmpResponse:src icmp_type icmp_code ttl ident seq payload, methodis_echo_reply()ArpReply:ip mac ifaceSniffedPacket:iface bytes ts_secs, methodethertype()
TCP flag constants
SYN, ACK, RST, FIN, PSH, URG, ECE, CWR — combine with | or pass a string like "SA" to flags=.
Not in v0.1 (planned)
- IPv6 (IPv4 only today)
- BPF filter expressions on
sniff - pcap read/write
- Multi-reply send (
srreturning a list) - Windows wheels (libpnet supports Windows via Npcap / winpkfilter — this wrapper just hasn't wired it up yet)
Build from source
Requires Rust (stable, 1.74+) and Python 3.10+.
git clone https://github.com/ropoctl/libpnet-pyo3
cd libpnet-pyo3
python -m venv .venv && source .venv/bin/activate
pip install maturin
maturin develop --release
License
Dual-licensed under Apache-2.0 or MIT at your option.
Metadata
Release files for libpnet-pyo3 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| libpnet_pyo3-0.1.2.tar.gz | 25.1 kB | With provenance | Details for libpnet_pyo3-0.1.2.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ x86-64 | Details for libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
| libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.17+ ARM64 | Details for libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
| libpnet_pyo3-0.1.2-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) | Details for libpnet_pyo3-0.1.2-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
Total release size: 1.2 MB
Release files / libpnet_pyo3-0.1.2.tar.gz
| Download URL | libpnet_pyo3-0.1.2.tar.gz |
|---|---|
| Size | 25.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd4ebe0da7a2d4515a999d37799e18e9abe66691ccceb264df533466a7ff8958
|
|
BLAKE2b-256 checksum How to use checksums |
3c7f2a4eb81e1d078b7df7a9d601d3eabb93172a2a13cc3328381121b798d62d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.
Transparency logRelease files / libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 302.2 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
07f3285c4827a18c134c305e50786a96a9cbd52e9d2e46e1141a0b606227f38d
|
|
BLAKE2b-256 checksum How to use checksums |
041bfc3ef9cb13db00c1b590f5b672bc970744a569b13ecc4531d003b3de7039
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.
Transparency logRelease files / libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | libpnet_pyo3-0.1.2-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 292.3 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
01de212e99308a1a42cb7f8e3066133779df953ac9e77c743026bb7f276f2983
|
|
BLAKE2b-256 checksum How to use checksums |
0e1d41e1da383d846da60fb307ae81f7a31e1507d4fbe1177e2449fd5390787f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.
Transparency logRelease files / libpnet_pyo3-0.1.2-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | libpnet_pyo3-0.1.2-cp310-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 548.7 kB |
| Tags | CPython 3.10 abi3 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
456f92a2eb7bb7146381ebf4a649d09542bf5a172b5adac5448f4de8f06ca6f3
|
|
BLAKE2b-256 checksum How to use checksums |
01fe1a4033ce6aebee00f861cc8480bca560e3d6355fadc42a25c1970e14a5bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.
Transparency logSecurity for libpnet-pyo3 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for libpnet_pyo3-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.