{"id":2617,"library":"netifaces","title":"Portable Network Interface Information","description":"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.","status":"maintenance","version":"0.11.0","language":"en","source_language":"en","source_url":"https://github.com/al45tair/netifaces","tags":["networking","network interfaces","IP address","gateways","system information"],"install":[{"cmd":"pip install netifaces","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"netifaces","correct":"import netifaces"}],"quickstart":{"code":"import netifaces\n\n# Get a list of all network interface names\ninterfaces = netifaces.interfaces()\nprint(f\"Interfaces: {interfaces}\")\n\n# Get addresses for a specific interface (e.g., the first one found)\nif interfaces:\n    first_interface = interfaces[0]\n    addresses = netifaces.ifaddresses(first_interface)\n    print(f\"Addresses for {first_interface}:\\n{addresses}\")\n\n    # Example: Accessing IPv4 addresses if available\n    if netifaces.AF_INET in addresses:\n        ipv4_addresses = addresses[netifaces.AF_INET]\n        print(f\"IPv4 addresses on {first_interface}: {ipv4_addresses}\")\n\n# Get default gateway information\ngateways = netifaces.gateways()\nprint(f\"Gateways: {gateways}\")\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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`.","severity":"deprecated","affected_versions":"<=0.11.0"},{"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`.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Installing `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"On 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.","severity":"gotcha","affected_versions":"0.11.0 (on Windows)"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}