netimps
The network utilities every tool ends up rewriting — interface discovery,
"which is my IP", reachability checks, CIDR maths, host:port parsing, DNS,
ping, scanning and multicast — as one typed, flat-import library.
Built on the standard library: the only runtime dependency is dnspython, and
only resolve() uses it. Interface enumeration, routing and multicast are
ctypes bindings to the platform's own APIs, so there is nothing to compile
and no wheel to miss for your platform.
Installation
pip install netimps
Requires Python 3.9+.
30-second tour
import netimps
from netimps import IPNetwork, MACAddress, parse
# Interfaces: names, MACs, MTU and real prefixes on every OS
for iface in netimps.get_interfaces():
print(iface.name, iface.mac, iface.mtu, [str(ip) for ip in iface.ips])
# One parsing entry point; types are what you annotate with
parse("10.0.0.5/24", IPNetwork) # IPv4Network('10.0.0.0/24')
netimps.try_parse("nope", netimps.IPAddress) # None
# Which of my addresses actually reaches that host?
netimps.get_source_ip("8.8.8.8") # IPv4Address(...)
# The honest reachability test
netimps.tcp_check("example.com", 443) # True
Design notes
A few behaviours are deliberate:
Interface.is_loopbackis computed from addresses, not names —lo,lo0andLoopback Pseudo-Interface 1share no spelling.- Concrete types are strict about family.
parse("::1", IPAddress)works;parse("::1", IPv4Address)raises rather than quietly returning v6. resolveraises on a malformed query rather than returning[]— a typo'd record type should not look like "no such record".ping(ttl=...)behaves the same on every OS. Windowspingexits0for "TTL expired in transit", so the reply address is verified instead of trusting the exit code.discover_mtumeasures the real path, sending DF-flagged pings, whileget_pmtuonly reports what the kernel already cached (usually nothing, and never anything on Windows).
Learn more
- API Reference — every export, generated from the source.
- Changelog