Registry / http-networking / ifaddr

ifaddr

JSON →
library0.2.0pypypi✓ verified 24d ago

ifaddr is a small, cross-platform Python library designed for enumerating network interfaces and their associated IP addresses. It supports Linux, OS X, Windows, and is expected to work on other BSD derivatives and Solaris/Illumos. Released under the MIT License, the current version 0.2.0 (June 2022) works with Python 3.9+ and requires no compilation, simplifying installation.

pip install ifaddr
INSTALL
IMPORT
SIG · IFADDR
I
ifaddr
http-networkingpythonv0.2.0
Install
1.6s avg
Import
69ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.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
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.066s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.072s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

get_adapters
import ifaddr adapters = ifaddr.get_adapters()

This example demonstrates how to retrieve all network adapters and iterate through their configured IP addresses. It also shows how to include unconfigured adapters if needed.

import ifaddr # Get all network adapters adapters = ifaddr.get_adapters() for adapter in adapters: print(f"IPs of network adapter {adapter.nice_name}") if adapter.ips: for ip in adapter.ips: # ip.ip will be a string for IPv4, and a tuple (ip_str, flowinfo, scope_id) for IPv6 print(f" {ip.ip}/{ip.network_prefix}") else: print(" No IPs configured") # To include interfaces without configured IP addresses: # adapters_with_unconfigured = ifaddr.get_adapters(include_unconfigured=True)
Debug
Known issues
breakingVersion 0.2.0 dropped support for Python 3.6.
fix
Upgrade to Python 3.7+ (preferably 3.9+ as per the latest README) if using ifaddr 0.2.0 or newer.
affects: 0.2.0 and later
gotchaBy default, `ifaddr.get_adapters()` only returns interfaces with configured IP addresses. To include interfaces without any assigned IP, pass `include_unconfigured=True`.
fix
Use `ifaddr.get_adapters(include_unconfigured=True)` to retrieve all interfaces, regardless of IP configuration.
affects: All versions
gotchaFor IPv6 addresses, the `ip.ip` attribute returns a three-tuple: `(ip_address_string, flowinfo, scope_id)`, not just a string, which might require unpacking or specific handling.
fix
Be aware that `ip.ip` for IPv6 addresses is a tuple. Access the string representation as `ip.ip[0]` if only the address string is needed.
affects: All versions
gotchaOn Windows, the `adapter.name` property returns a UUID string, not a human-readable name. Use `adapter.nice_name` for a more descriptive identifier.
fix
Prefer `adapter.nice_name` for displaying adapter names to users, especially on Windows.
affects: All versions
gotchaWhile `ifaddr` is lightweight and doesn't require compilation, the `netifaces` library offers more comprehensive network interface information. As of `ifaddr` 0.2.0, an equivalent to `netifaces.interfaces()` is available at `ifaddr.netifaces.interfaces()`.
fix
Consider `netifaces` if more in-depth interface details (e.g., multicast addresses, status flags) are required, acknowledging its compilation dependency. For a subset of `netifaces` functionality, explore `ifaddr.netifaces` module.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ifaddr'
The 'ifaddr' package is not installed in the Python environment where the code is being executed.
fix
Install the 'ifaddr' package using pip: `pip install ifaddr`
AttributeError: module 'ifaddr' has no attribute 'get_adapters'
The `get_adapters` function is either misspelled, or a local Python file named `ifaddr.py` is shadowing the installed 'ifaddr' package, causing Python to import the local file instead of the library.
fix
Ensure `ifaddr.get_adapters()` is spelled correctly. If a local file named `ifaddr.py` exists in your project directory, rename it to avoid conflicting with the installed library. The correct import and usage pattern is typically: `import ifaddr; adapters = ifaddr.get_adapters()`.
AttributeError: 'ifaddr.IP' object has no attribute 'address'
Users attempting to access the IP address from an `ifaddr.IP` object often use a common attribute name like 'address', but the library exposes the IP address value via the 'ip' attribute.
fix
Access the IP address using the `ip` attribute: `ip_object.ip` (e.g., `print(ip.ip)`).
Upgrade
Version history
0.2.0latest on PyPI · released Jun 15, 2022
Audit
Dependencies
pythonrequiredRuntime environment. Requires Python 3.9+ as of version 0.2.0.
Agent activity
11 hits · last 30 days
node
10
Resources