Registry / http-networking / netifaces

netifaces

JSON →
library0.11.0pypypi✓ verified 24d ago

netifaces is a Python library that provides a portable way to access network interface information, including IP addresses, netmasks, broadcast addresses, and gateway details. It supports various operating systems such as OS X, Linux, and Windows. The current version is 0.11.0, but the original project is no longer actively maintained. Forks exist to provide continued support and new features.

pip install netifaces
INSTALL
IMPORT
SIG · NETIFACES
N
netifaces
http-networkingpythonv0.11.0
Install
1.8s avg
Import
Disk
18MB
Pass rate
1/ 10
Env Coverage1 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.11.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✕ build_error
py 3.11
✕ build_error
✕ build_error
py 3.12
✕ build_error
✕ build_error
py 3.13
✕ build_error
✕ build_error
py 3.9
✕ build_error
✓ 1.8s
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

netifaces
import netifaces

This quickstart demonstrates how to list network interfaces, retrieve detailed address information for a specific interface, and fetch default gateway settings. Note that the output structure for `ifaddresses` is a dictionary keyed by system-dependent address family constants.

import netifaces # Get a list of all network interface names interfaces = netifaces.interfaces() print(f"Interfaces: {interfaces}") # Get addresses for a specific interface (e.g., the first one found) if interfaces: first_interface = interfaces[0] addresses = netifaces.ifaddresses(first_interface) print(f"Addresses for {first_interface}:\n{addresses}") # Example: Accessing IPv4 addresses if available if netifaces.AF_INET in addresses: ipv4_addresses = addresses[netifaces.AF_INET] print(f"IPv4 addresses on {first_interface}: {ipv4_addresses}") # Get default gateway information gateways = netifaces.gateways() print(f"Gateways: {gateways}")
Debug
Known issues
deprecatedThe original `netifaces` library (version 0.11.0 and earlier) is no longer actively maintained by its original author (al45tair) since at least May 2021. This means no new features, official bug fixes, or updates for newer Python versions are expected for this package. Users needing active development or support for modern Python versions should consider actively maintained forks like `netifaces2` or `netifaces-plus`.
fix
For ongoing development and support, consider migrating to `netifaces2` (`pip install netifaces2`) or `netifaces-plus` (`pip install netifaces-plus`). Be aware that these forks may introduce API changes.
affects: <=0.11.0
gotchaThe numeric values of address family constants (e.g., `netifaces.AF_INET`, `netifaces.AF_LINK`) are system-dependent and can vary across different operating systems or even kernel versions. Do not assume fixed integer values or interchange them directly with constants from Python's `socket` module, as their underlying values might differ.
fix
Always use the symbolic constants provided directly by the `netifaces` module (e.g., `netifaces.AF_INET`) when querying `ifaddresses` results, rather than hardcoded integers or `socket.AF_INET`.
affects: All versions
gotchaThe output of `netifaces.ifaddresses(interface_name)` is a dictionary keyed by system-dependent address family integers. Each value is a list of dictionaries, where each inner dictionary represents an address. This nested structure can appear cryptic and requires careful parsing, as a single interface can have multiple addresses of the same family.
fix
Iterate through the `addresses` dictionary and its lists, explicitly checking for desired address families (e.g., `if netifaces.AF_INET in addresses: ...`) and iterating through the list of addresses for that family.
affects: All versions
gotchaInstalling `netifaces` from source distribution (e.g., a `.tar.gz` file or directly from GitHub without pre-compiled wheels) requires platform-specific development tools, including a C compiler and Python development headers. Missing these tools will result in compilation errors during installation.
fix
Ensure that your system has the necessary build tools installed (e.g., `build-essential` on Debian/Ubuntu, Xcode Command Line Tools on macOS, or Visual C++ build tools on Windows). Preferably, use `pip install netifaces` in an environment where pre-compiled wheels are available for your Python version and OS.
affects: All versions
gotchaOn Windows, the `netifaces` library (version 0.11.0) might not report IPv4 addresses for network interfaces that have static IP configurations but are currently in a 'down' state. IPv6 addresses are generally reported regardless of interface status.
fix
If working with Windows and needing to retrieve IPv4 addresses, ensure the target network interface is active ('up'). Forks like `netifaces2` introduced `netifaces.interface_is_up()` to explicitly check interface status, which might be a necessary check if migrating or dealing with such scenarios.
affects: 0.11.0 (on Windows)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'netifaces'
The `netifaces` package is not installed in the Python environment being used, or there are conflicting Python installations where it's installed for one but not the active one.
fix
Install the package using pip: `pip install netifaces`. If using a specific Python version, use `python3 -m pip install netifaces` or `python -m pip install netifaces`. For Ubuntu/Debian, `sudo apt install python3-netifaces` might also be necessary.
ImportError: No module named netifaces
The `netifaces` package cannot be found by the Python interpreter, typically because it's not installed or there's a mismatch between the `pip` installation and the Python executable being run.
fix
Ensure `netifaces` is installed for the correct Python interpreter by running `pip install netifaces` (or `pip3 install netifaces` for Python 3). If multiple Python versions are present, explicitly use `python -m pip install netifaces` or `python3 -m pip install netifaces` to ensure the package is installed into the desired environment.
error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/visual-cpp-build-tools
On Windows, `netifaces` includes C extensions that need to be compiled during installation, and the necessary C++ build tools are missing.
fix
Download and install the 'Build Tools for Visual Studio' from the provided Microsoft link. During installation, make sure to select the C++ build tools. After installation, try `pip install netifaces` again.
ImportError: /home/user/.local/lib/python2.7/site-packages/netifaces.so: undefined symbol: _Py_ZeroStruct
This error typically indicates an incompatibility between the compiled `netifaces.so` module and the Python interpreter, often due to building the module against one Python version/configuration and then trying to use it with another, or issues with system-wide Python installations and specific virtual environments.
fix
Ensure `netifaces` is installed for the *exact* Python interpreter you are using. This often means reinstalling it within the specific environment (e.g., virtual environment or a specific Python installation) with `pip install --no-binary :all: netifaces` to force a fresh compilation, or verifying that the correct Python environment is active before installation.
Upgrade
Version history
0.11.0latest on PyPI · released May 31, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
10
OpenAI (training)
2
Resources
netifaces — pip install netifaces · libregistry