{"id":9980,"library":"netifaces2","title":"Portable Network Interface Information (Fork)","description":"netifaces2 is a Python library providing portable access to network interface information. It is a fork of the original `netifaces` library, offering improved support, particularly for Windows, and is actively maintained. The current version is 0.0.22, with recent updates focusing on stability and new features like listing interfaces by name and index, enhancing Windows compatibility.","status":"active","version":"0.0.22","language":"en","source_language":"en","source_url":"https://github.com/SamuelYvon/netifaces-2","tags":["network","interface","system-info","network-address"],"install":[{"cmd":"pip install netifaces2","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"netifaces2 is a distinct, actively maintained fork of the original netifaces package. Ensure you import the correct package.","wrong":"import netifaces\nnetifaces.interfaces()","symbol":"interfaces","correct":"import netifaces2\nnetifaces2.interfaces()"},{"note":"Ensure you are importing from the 'netifaces2' package for current features and fixes.","wrong":"import netifaces\nnetifaces.ifaddresses('eth0')","symbol":"ifaddresses","correct":"import netifaces2\nnetifaces2.ifaddresses('eth0')"},{"note":"Constants like AF_INET are re-exported by netifaces2. Always import from the 'netifaces2' package.","wrong":"from netifaces import AF_INET","symbol":"AF_INET","correct":"from netifaces2 import AF_INET"}],"quickstart":{"code":"import netifaces2\n\nprint(f\"All interfaces: {netifaces2.interfaces()}\")\n\nfor i in netifaces2.interfaces():\n    print(f\"\\nInterface: {i}\")\n    addrs = netifaces2.ifaddresses(i)\n    if netifaces2.AF_INET in addrs:\n        for link in addrs[netifaces2.AF_INET]:\n            print(f\"  IPv4: {link.get('addr')}\")\n    if netifaces2.AF_INET6 in addrs:\n        for link in addrs[netifaces2.AF_INET6]:\n            print(f\"  IPv6: {link.get('addr')}\")\n    if netifaces2.AF_LINK in addrs:\n        for link in addrs[netifaces2.AF_LINK]:\n            print(f\"  MAC: {link.get('addr')}\")","lang":"python","description":"This example demonstrates how to list all network interfaces and retrieve their IPv4, IPv6, and MAC addresses using `netifaces2`."},"warnings":[{"fix":"Always use `pip install netifaces2` and `import netifaces2` in your code.","message":"Users migrating from the original `netifaces` library might mistakenly install or import `netifaces` instead of `netifaces2`. These are distinct packages, and `netifaces2` is the actively maintained fork.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure you are running netifaces2 version 0.0.22 or newer for improved Windows stability by running `pip install --upgrade netifaces2`. Report specific issues to the GitHub repository.","message":"On Windows, prior to version 0.0.22, users might encounter stability issues, including potential unbounded memory allocations, particularly on complex network setups.","severity":"gotcha","affected_versions":"<0.0.22 (Windows only)"},{"fix":"Use `netifaces2.interfaces()` to dynamically get a list of available interfaces and iterate through them, or use platform-specific logic to resolve common interface names.","message":"Network interface names can vary significantly across operating systems (e.g., 'eth0', 'en0', 'Local Area Connection'). Hardcoding interface names can lead to non-portable code.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Run `pip install netifaces2` in your active Python environment.","cause":"The netifaces2 package is not installed in the active Python environment.","error":"ModuleNotFoundError: No module named 'netifaces2'"},{"fix":"Ensure you have `netifaces2` installed (`pip install netifaces2`) and are importing it correctly: `import netifaces2`.","cause":"You intended to use `netifaces2` but imported the original `netifaces` package, which might not be installed or has an incompatible API.","error":"AttributeError: module 'netifaces' has no attribute 'interfaces'"},{"fix":"Always check if the address family exists in the returned dictionary before accessing it, e.g., `if netifaces2.AF_INET in addrs:`.","cause":"The specified network interface does not have an address configured for the requested address family (e.g., no IPv4 address for AF_INET).","error":"KeyError: 2 (or other address family constants like 17 or 18) when accessing `addrs[netifaces2.AF_INET]`"},{"fix":"Upgrade to netifaces2 version 0.0.22 or newer (`pip install --upgrade netifaces2`) which includes several Windows memory fixes.","cause":"Older versions of netifaces2 on Windows had known memory management issues, particularly with complex network configurations.","error":"Memory allocation issues on Windows (application uses excessive RAM or crashes)"}]}