netifaces

Portable, cross-platform access to your machine's network interface addresses from Python

Library
PyPI
v0.11.0
338stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
35/100Needs Attention
Development Activity0
Maintenance0
Community60
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
71/100Good
Architecture70
Code Quality62
Innovation68
Learning Curve85

netifaces is a small, portable Python library that lets you enumerate a machine’s network interfaces and read their addresses without writing platform-specific low-level networking code. Implemented as a C extension, it papers over the substantial differences between operating systems so the same Python calls work on Linux, macOS, Windows, and other UNIX-like systems.

The library exposes a handful of simple functions that return interface names, IPv4 and IPv6 addresses, netmasks, broadcast and peer addresses, hardware (MAC) addresses, and the routing gateways configured on the host. It is widely depended upon across the Python ecosystem wherever a program needs to discover how a machine is connected to the network.

What You Get

  • A cross-platform interfaces() call that lists every network interface identifier on the host
  • ifaddresses() returning IPv4, IPv6, and link-layer addresses keyed by address family
  • gateways() reporting per-family routing gateways plus the system default
  • Address-family constants (AF_INET, AF_INET6, AF_LINK) that are correct for the current platform

Common Use Cases

  • Discovering a server’s own IP addresses at runtime for binding or reporting
  • Reading the MAC address of an interface for licensing or device identification
  • Determining the default gateway to make network-topology decisions
  • Enumerating available interfaces in network diagnostic and monitoring tools

Under The Hood

Architecture - The entire library is a single CPython C extension (netifaces.c, ~79KB) that registers three public functions (interfaces, ifaddresses, gateways) plus platform-resolved address-family constants; at import time it probes which OS facilities are available (getifaddrs, SIOCGIFHWADDR, sysctl/route sockets, Windows IP Helper API) and dispatches to the appropriate branch, marshalling native address structures into Python dicts and lists. Tech Stack - Written in C against the CPython C-API with a large setup.py (~20KB) that performs feature detection at build time to compile the right code paths per platform; there are no Python or third-party runtime dependencies. Code Quality - The code is mature and battle-tested with heavy per-platform conditional compilation; a minimal test.py exercises the public functions but coverage is light, and the project is explicitly in maintenance-only status with its author seeking a new maintainer. API Design - The public surface is tiny and easy to learn: a few functions returning plain data structures keyed by address-family constants, well documented in the README, though callers must understand that interfaces can have multiple addresses per family and that constant values are platform-dependent.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search