netifaces-plus
raw JSON → 0.12.5 verified Fri May 01 auth: no python
A portable library to retrieve network interface information (IP addresses, MAC addresses, gateways, etc.) on Unix, Windows, and macOS. Version 0.12.5 supports Python >=3.6. Fork of the unmaintained netifaces with modern Python support and additional features. Released irregularly.
pip install netifaces-plus Common errors
error ModuleNotFoundError: No module named 'netifaces_plus' ↓
cause User tried to import the package with the PyPI name (netifaces-plus) as the module name.
fix
Use 'import netifaces' instead of 'import netifaces_plus'.
error AttributeError: module 'netifaces' has no attribute 'interfaces' ↓
cause The module might not be the real netifaces-plus (perhaps a stale or different package).
fix
Ensure you installed netifaces-plus (not netifaces) and check the version:
pip show netifaces-plus. error KeyError: 2 (or AF_INET not found) ↓
cause The interface does not have an IPv4 address (e.g., no IP assigned).
fix
Check with
if netifaces.AF_INET in addrs before accessing addrs[netifaces.AF_INET]. Warnings
gotcha The PyPI package name is 'netifaces-plus' but the Python import is 'netifaces'. This often confuses users who try 'import netifaces_plus'. ↓
fix Use 'import netifaces'.
gotcha On some platforms (e.g., Windows), 'ifaddresses(MY_IFACE)' may return empty or partial data if the interface is down or not fully initialized. Always handle missing keys. ↓
fix Check if address family exists: `netifaces.AF_INET in addrs`.
breaking In version 0.12.4, the library dropped support for Python 3.5 and below. Users on older Python must pin to an older release. ↓
fix Upgrade Python to 3.6+ or use 'pip install netifaces-plus<0.12.4'.
gotcha The 'gateways()' function returns a dict where keys are address families (e.g., AF_INET, AF_INET6) and values are lists. The default gateway is the first element of the list, not a separate key. ↓
fix Access default IPv4 gateway with `netifaces.gateways()['default'][netifaces.AF_INET]`.
Imports
- netifaces wrong
import netifaces_pluscorrectimport netifaces - interfaces wrong
netifaces.networks()correctnetifaces.interfaces() - gateways wrong
netifaces.default_gateway()correctnetifaces.gateways()
Quickstart
import netifaces
# List all network interface names
ifaces = netifaces.interfaces()
print('Interfaces:', ifaces)
# Get addresses for a specific interface (e.g., 'eth0' or 'en0')
if ifaces:
iface = ifaces[0]
addrs = netifaces.ifaddresses(iface)
print(f'Addresses for {iface}:', addrs)
# Get default gateways
print('Gateways:', netifaces.gateways())