### Install netifaces-2 Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md Use pip to install the netifaces-2 package. ```shell pip install netifaces2 ``` -------------------------------- ### Set up local development environment Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md Steps to set up a local development environment for netifaces-2. This includes installing Rust, creating a virtual environment, installing the package in editable mode with development dependencies, and setting up pre-commit hooks. ```bash python3 -m venv venv source venv/bin/activate (or .\venv\Scripts\activate.ps1 with Windows Powershell) python3 -m pip install -e '.[dev]' # This internally runs the Rust compiler python3 -m pip install pre-commit source venv/bin/activate # Re-source the venv to pick up new scripts pre-commit install ``` -------------------------------- ### Install netifaces-2 using pip Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md Install the netifaces-2 package using pip. This command installs wheels for Linux, Windows, and macOS, requiring Python 3.7 or newer. ```bash python -m pip install netifaces2 ``` -------------------------------- ### Basic netifaces-2 Usage Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md Import the library and use its functions to get network interface information. Refer to the original netifaces documentation for detailed usage. ```python >>> import netifaces >>> netifaces.interfaces() ... ``` ```python >>> netifaces.ifaddresses('en0') ... ``` ```python >>> netifaces.gateways() ... ``` -------------------------------- ### Complete Example: Replica of `ip addr` Source: https://context7.com/samuelyvon/netifaces-2/llms.txt This script enumerates all interfaces, prints their status, MAC address, and IPv4/IPv6 addresses with CIDR prefix lengths, similar to the 'ip addr' command. ```python #!/usr/bin/env python3 import ipaddress import netifaces from netifaces import InterfaceType, InterfaceDisplay def prefix_len_v6(netmask: str) -> int: bit_count = [0,0x8000,0xC000,0xE000,0xF000,0xF800,0xFC00,0xFE00, 0xFF00,0xFF80,0xFFC0,0xFFE0,0xFFF0,0xFFF8,0xFFFC,0xFFFE,0xFFFF] count = 0 for w in netmask.split(":"): if not w or int(w, 16) == 0: break count += bit_count.index(int(w, 16)) return count all_ifaces = dict(sorted(netifaces.interfaces_by_index(InterfaceDisplay.HumanReadable).items())) for index, name in all_ifaces.items(): status = "UP" if netifaces.interface_is_up(name) else "DOWN" print(f"{index}: {name}: <{status}>") addrs = netifaces.ifaddresses(name) # MAC address for entry in addrs.get(InterfaceType.AF_PACKET, []): brd = f" brd {entry['broadcast']}" if "broadcast" in entry else "" print(f" link/ether {entry['addr']}{brd}") # IPv4 for entry in addrs.get(InterfaceType.AF_INET, []): net = ipaddress.IPv4Network(f"{entry['addr']}/{entry.get('mask','32')}", strict=False) brd = f" brd {entry['broadcast']}" if "broadcast" in entry else "" print(f" inet {entry['addr']}/{net.prefixlen}{brd}") # IPv6 for entry in addrs.get(InterfaceType.AF_INET6, []): mask = entry.get("mask", "") plen = f"/{prefix_len_v6(mask)}" if mask else "" print(f" inet6 {entry['addr']}{plen}) ``` -------------------------------- ### Iterate All Interfaces and Collect IPv4 Addresses Source: https://context7.com/samuelyvon/netifaces-2/llms.txt This snippet demonstrates how to iterate through all network interfaces on a system and collect all associated IPv4 addresses. It requires the netifaces library to be installed. ```python import netifaces all_ipv4 = {} for name in netifaces.interfaces(): table = netifaces.ifaddresses(name) if netifaces.AF_INET in table: all_ipv4[name] = [e["addr"] for e in table[netifaces.AF_INET]] print(all_ipv4) ``` -------------------------------- ### Get System Routing Table with netifaces.gateways() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Retrieves system routing entries keyed by InterfaceType. Requires the 'ip' command or readable /proc/net/route on Linux; Windows support is not yet functional. Pass old_api=True for integer keys. ```python import netifaces from netifaces import InterfaceType try: routes = netifaces.gateways() except NotImplementedError as e: print(f"Gateway lookup not supported on this platform: {e}") routes = {} # IPv4 routes if InterfaceType.AF_INET in routes: for entry in routes[InterfaceType.AF_INET]: gateway_ip, iface_name = entry[0], entry[1] is_default = entry[2] if len(entry) > 2 else False print(f" IPv4 gateway {gateway_ip} via {iface_name} {'(default)' if is_default else ''}") # IPv6 routes if InterfaceType.AF_INET6 in routes: for entry in routes[InterfaceType.AF_INET6]: print(f" IPv6 gateway {entry[0]} via {entry[1]}") # old_api=True returns integer keys (original netifaces behaviour) old_routes = netifaces.gateways(old_api=True) print(old_defaults) ``` -------------------------------- ### List all network interfaces Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Get a list of all network interface names. On Windows, an optional InterfaceDisplay hint can control the name format (human-readable or machine-readable UUID). ```python import netifaces from netifaces import InterfaceDisplay # Default: human-readable names on all platforms iface_names = netifaces.interfaces() print(iface_names) # Example output (Linux): ['lo', 'eth0', 'wlan0'] # Example output (macOS): ['lo0', 'en0', 'utun0'] ``` ```python # Windows: human-readable adapter descriptions human = netifaces.interfaces(InterfaceDisplay.HumanReadable) print(human) # ['Realtek PCIe GbE Family Controller', 'Intel(R) Wi-Fi 6 AX200'] ``` ```python # Windows: machine-readable UUID format machine = netifaces.interfaces(InterfaceDisplay.MachineReadable) print(machine) # ['{E5993936-7D91-44DD-84FD-55D909FF2143}', '{A1B2C3D4-...}'] ``` -------------------------------- ### Get Default Gateway in netifaces-2 Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md Use `netifaces.default_gateway()` to retrieve the default gateway for each interface type. This replaces the indexing by `default` in the original library. The result may be an empty dictionary if no default route is set. ```python >>> netifaces.default_gateway() ... ``` -------------------------------- ### Get all addresses for a network interface Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Retrieve a dictionary of addresses for a specified interface, keyed by InterfaceType enum values. Each entry contains address details like 'addr', 'mask', 'broadcast', or 'peer'. Raises an exception if the interface does not exist. ```python import netifaces from netifaces import InterfaceType iface = "eth0" # Replace with an interface from netifaces.interfaces() try: addrs = netifaces.ifaddresses(iface) except Exception as e: print(f"Interface lookup failed: {e}") raise ``` ```python # --- IPv4 addresses --- if InterfaceType.AF_INET in addrs: for entry in addrs[InterfaceType.AF_INET]: print(f"IPv4 addr: {entry['addr']}") print(f"IPv4 netmask: {entry.get('mask', 'n/a')}") print(f"IPv4 broadcast: {entry.get('broadcast', 'n/a')}") # IPv4 addr: 192.168.1.42 # IPv4 netmask: 255.255.255.0 # IPv4 broadcast: 192.168.1.255 ``` ```python # --- IPv6 addresses --- if InterfaceType.AF_INET6 in addrs: for entry in addrs[InterfaceType.AF_INET6]: print(f"IPv6 addr: {entry['addr']}") print(f"IPv6 netmask: {entry.get('mask', 'n/a')}") # IPv6 addr: fe80::1a2b:3c4d:5e6f:7a8b%eth0 # IPv6 netmask: ffff:ffff:ffff:ffff:: ``` ```python # --- MAC / link-layer address (AF_LINK is an alias for AF_PACKET) --- if InterfaceType.AF_LINK in addrs: for entry in addrs[InterfaceType.AF_LINK]: print(f"MAC addr: {entry['addr']}") print(f"MAC broadcast: {entry.get('broadcast', 'n/a')}") # MAC addr: aa:bb:cc:dd:ee:ff ``` -------------------------------- ### Get Default Gateway with netifaces.default_gateway() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt A convenience function that filters gateways() to return only the single default gateway for each interface type. Returns an empty dict if no default route is configured. old_api=True mirrors original netifaces integer keys. ```python import netifaces from netifaces import InterfaceType try: defaults = netifaces.default_gateway() except NotImplementedError as e: print(f"Not supported: {e}") defaults = {} print(defaults) # Look up the default IPv4 gateway if InterfaceType.AF_INET in defaults: gw_ip, gw_iface = defaults[InterfaceType.AF_INET] print(f"Default IPv4 gateway: {gw_ip} on {gw_iface}") else: print("No default IPv4 gateway") # old_api=True mirrors original netifaces integer keys old_defaults = netifaces.default_gateway(old_api=True) ``` -------------------------------- ### netifaces.interfaces() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Lists all network interface names available on the machine. Accepts an optional InterfaceDisplay hint to control name format on Windows. ```APIDOC ## netifaces.interfaces() ### Description Returns a list of all network interface names available on the machine. Accepts an optional `InterfaceDisplay` hint that controls the name format returned on Windows (human-readable adapter description vs. machine-readable UUID). On POSIX platforms the display hint is ignored and the device name (e.g. "lo", "eth0") is always returned. ### Method `netifaces.interfaces(display_hint: InterfaceDisplay = InterfaceDisplay.HumanReadable)` ### Parameters #### Query Parameters - **display_hint** (`InterfaceDisplay`) - Optional - Controls the name format returned on Windows. Defaults to `InterfaceDisplay.HumanReadable`. ### Request Example ```python import netifaces from netifaces import InterfaceDisplay # Default: human-readable names on all platforms iface_names = netifaces.interfaces() print(iface_names) # Windows: human-readable adapter descriptions human = netifaces.interfaces(InterfaceDisplay.HumanReadable) print(human) # Windows: machine-readable UUID format machine = netifaces.interfaces(InterfaceDisplay.MachineReadable) print(machine) ``` ### Response #### Success Response - **list** (list of strings) - A list of network interface names. ``` -------------------------------- ### netifaces.interfaces_by_index() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Returns a dictionary mapping each interface's numeric system index to its name. Accepts the same InterfaceDisplay hint as interfaces(). ```APIDOC ## netifaces.interfaces_by_index() ### Description Returns a dictionary mapping each interface's numeric system index to its name. Accepts the same `InterfaceDisplay` hint as `interfaces()`. Useful when you need to correlate interface information across tools that refer to interfaces by index. ### Method `netifaces.interfaces_by_index(display_hint: InterfaceDisplay = InterfaceDisplay.HumanReadable)` ### Parameters #### Query Parameters - **display_hint** (`InterfaceDisplay`) - Optional - Controls the name format returned on Windows. Defaults to `InterfaceDisplay.HumanReadable`. ### Request Example ```python import netifaces from netifaces import InterfaceDisplay # Get index → name mapping (human-readable, default) by_index = netifaces.interfaces_by_index() print(by_index) # Sort by index to process interfaces in a deterministic order sorted_ifaces = dict(sorted(netifaces.interfaces_by_index().items())) for idx, name in sorted_ifaces.items(): print(f" [{idx}] {name}") # Verify both functions return the same set of interfaces assert set(netifaces.interfaces_by_index().values()) == set(netifaces.interfaces()) ``` ### Response #### Success Response - **dict** (dict) - A dictionary where keys are interface indices (int) and values are interface names (str). ``` -------------------------------- ### List interfaces keyed by system index Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Obtain a dictionary mapping interface system indices to their names. This is useful for correlating interface information across different tools. An InterfaceDisplay hint can be provided for Windows. ```python import netifaces from netifaces import InterfaceDisplay # Get index → name mapping (human-readable, default) by_index = netifaces.interfaces_by_index() print(by_index) # Example output: {1: 'lo', 2: 'eth0', 3: 'wlan0'} ``` ```python # Sort by index to process interfaces in a deterministic order sorted_ifaces = dict(sorted(netifaces.interfaces_by_index().items())) for idx, name in sorted_ifaces.items(): print(f" [{idx}] {name}") # [1] lo # [2] eth0 # [3] wlan0 ``` ```python # Verify both functions return the same set of interfaces assert set(netifaces.interfaces_by_index().values()) == set(netifaces.interfaces()) ``` -------------------------------- ### netifaces.interface_is_up() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Checks if a network interface is administratively up and has a physical link. It's recommended to combine this with address verification for portability. ```APIDOC ## netifaces.interface_is_up() ### Description Returns `True` if the named interface is administratively up **and** has a physical link (cable/wireless association). On macOS, the OS may incorrectly report disconnected Ethernet ports as running — for maximum portability, combine this check with verifying that the interface has addresses assigned. ### Method `interface_is_up(interface_name: str) -> bool` ### Parameters #### Path Parameters - **interface_name** (str) - Required - The name of the network interface to check. ### Request Example ```python import netifaces try: up = netifaces.interface_is_up("eth0") print(f"eth0 is {'up' if up else 'down'}") except Exception as e: print(f"Error checking interface: {e}") # Raises on invalid interface name try: netifaces.interface_is_up("nonexistent0") except Exception as e: print(f"Expected error: {e}") ``` ### Response #### Success Response (bool) - **True**: If the interface is up and has a link. - **False**: If the interface is down or lacks a physical link. #### Response Example ``` eth0 is up ``` ### Error Handling - Raises an exception if the interface name is invalid or an OS error occurs. ``` -------------------------------- ### netifaces.gateways() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Retrieves the system's routing table, categorized by interface type. Supports IPv4 and IPv6 routes. ```APIDOC ## netifaces.gateways() ### Description Returns a dictionary of routing entries keyed by `InterfaceType`. Each value is a list of tuples `(gateway_ip, interface_name)` or `(gateway_ip, interface_name, is_default)`. On Linux, this requires either the `ip` command-line tool or a readable `/proc/net/route` file. Windows gateway support is not yet functional. Pass `old_api=True` to get integer-keyed results compatible with the original `netifaces` library. ### Method `gateways(old_api: bool = False) -> dict` ### Parameters #### Query Parameters - **old_api** (bool) - Optional - If `True`, returns integer-keyed results compatible with the original `netifaces` library. ### Response #### Success Response (dict) A dictionary where keys are `InterfaceType` (or integers if `old_api=True`) and values are lists of tuples representing routes. Each tuple can be `(gateway_ip, interface_name)` or `(gateway_ip, interface_name, is_default)`. #### Response Example ```python import netifaces from netifaces import InterfaceType try: routes = netifaces.gateways() except NotImplementedError as e: print(f"Gateway lookup not supported on this platform: {e}") routes = {} # IPv4 routes if InterfaceType.AF_INET in routes: for entry in routes[InterfaceType.AF_INET]: gateway_ip, iface_name = entry[0], entry[1] is_default = entry[2] if len(entry) > 2 else False print(f" IPv4 gateway {gateway_ip} via {iface_name} {'(default)' if is_default else ''}") # IPv6 routes if InterfaceType.AF_INET6 in routes: for entry in routes[InterfaceType.AF_INET6]: print(f" IPv6 gateway {entry[0]} via {entry[1]}") # old_api=True returns integer keys (original netifaces behaviour) old_routes = netifaces.gateways(old_api=True) print(old_routes) ``` ### Error Handling - Raises `NotImplementedError` if gateway lookup is not supported on the platform. ``` -------------------------------- ### netifaces.default_gateway() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Retrieves the default gateway for each interface type, simplifying access to the primary route. ```APIDOC ## netifaces.default_gateway() ### Description Convenience function that filters `gateways()` and returns only the single default gateway entry for each interface type. The result is a dict mapping `InterfaceType` → `(gateway_ip, interface_name)`. Returns an empty dict if no default route is configured. ### Method `default_gateway(old_api: bool = False) -> dict` ### Parameters #### Query Parameters - **old_api** (bool) - Optional - If `True`, returns integer keys compatible with the original `netifaces` library. ### Response #### Success Response (dict) A dictionary mapping `InterfaceType` to a tuple `(gateway_ip, interface_name)` for the default gateway of each type. Returns an empty dictionary if no default route is configured. #### Response Example ```python import netifaces from netifaces import InterfaceType try: defaults = netifaces.default_gateway() except NotImplementedError as e: print(f"Not supported: {e}") defaults = {} print(defaults) # Look up the default IPv4 gateway if InterfaceType.AF_INET in defaults: gw_ip, gw_iface = defaults[InterfaceType.AF_INET] print(f"Default IPv4 gateway: {gw_ip} on {gw_iface}") else: print("No default IPv4 gateway") # old_api=True mirrors original netifaces integer keys old_defaults = netifaces.default_gateway(old_api=True) ``` ### Error Handling - Raises `NotImplementedError` if default gateway lookup is not supported on the platform. ``` -------------------------------- ### Interface Type Constants Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Use these constants with netifaces APIs. Do not mix with socket module constants as their values are not guaranteed to be consistent across platforms. ```python import netifaces from netifaces import InterfaceType # Module-level constants are also available as plain integers assert netifaces.AF_INET == InterfaceType.AF_INET # True assert netifaces.AF_INET6 == InterfaceType.AF_INET6 # True assert netifaces.AF_LINK == netifaces.AF_PACKET # True (aliases) # WARNING: do NOT mix with socket module constants import socket # socket.AF_INET == 2 on Linux (same coincidentally), but this is not guaranteed # for other families — always use netifaces.InterfaceType values with netifaces APIs print(f"AF_INET = {InterfaceType.AF_INET}") # AF_INET = 2 print(f"AF_INET6 = {InterfaceType.AF_INET6}") # AF_INET6 = 10 print(f"AF_LINK = {InterfaceType.AF_LINK}") # AF_LINK = 17 (== AF_PACKET) ``` -------------------------------- ### netifaces.ifaddresses() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Retrieves all addresses for a given network interface, keyed by InterfaceType enum values. ```APIDOC ## netifaces.ifaddresses() ### Description Returns a dictionary of addresses for the given interface name, keyed by `InterfaceType` enum values. Each value is a list of address-entry dicts; each dict may contain the keys `"addr"`, `"mask"`, `"broadcast"`, and/or `"peer"` depending on the address family. Raises an exception if the interface name does not exist. ### Method `netifaces.ifaddresses(interface_name: str)` ### Parameters #### Path Parameters - **interface_name** (str) - Required - The name of the network interface. ### Request Example ```python import netifaces from netifaces import InterfaceType iface = "eth0" # Replace with an interface from netifaces.interfaces() try: addrs = netifaces.ifaddresses(iface) except Exception as e: print(f"Interface lookup failed: {e}") raise # --- IPv4 addresses --- if InterfaceType.AF_INET in addrs: for entry in addrs[InterfaceType.AF_INET]: print(f"IPv4 addr: {entry['addr']}") print(f"IPv4 netmask: {entry.get('mask', 'n/a')}") print(f"IPv4 broadcast: {entry.get('broadcast', 'n/a')}") # --- IPv6 addresses --- if InterfaceType.AF_INET6 in addrs: for entry in addrs[InterfaceType.AF_INET6]: print(f"IPv6 addr: {entry['addr']}") print(f"IPv6 netmask: {entry.get('mask', 'n/a')}") # --- MAC / link-layer address (AF_LINK is an alias for AF_PACKET) --- if InterfaceType.AF_LINK in addrs: for entry in addrs[InterfaceType.AF_LINK]: print(f"MAC addr: {entry['addr']}") print(f"MAC broadcast: {entry.get('broadcast', 'n/a')}") ``` ### Response #### Success Response - **dict** (dict) - A dictionary where keys are `InterfaceType` enum values and values are lists of address dictionaries. Each address dictionary may contain `"addr"`, `"mask"`, `"broadcast"`, and `"peer"` keys. ``` -------------------------------- ### Check if an Interface is Active with netifaces.interface_is_up() Source: https://context7.com/samuelyvon/netifaces-2/llms.txt This function returns True if an interface is administratively up and has a physical link. On macOS, it may report disconnected ports as running, so combine with address verification for portability. It raises an exception for invalid interface names. ```python import netifaces from netifaces import InterfaceType def get_active_ipv4_interfaces(): """Return only interfaces that are up AND have an IPv4 address.""" active = {} for name in netifaces.interfaces(): if not netifaces.interface_is_up(name): continue # Skip interfaces that are down addrs = netifaces.ifaddresses(name) if InterfaceType.AF_INET in addrs: active[name] = [e["addr"] for e in addrs[InterfaceType.AF_INET]] return active print(get_active_ipv4_interfaces()) ``` ```python # Direct usage try: up = netifaces.interface_is_up("eth0") print(f"eth0 is {'up' if up else 'down'}") except Exception as e: print(f"Error checking interface: {e}") ``` ```python # Raises on invalid interface name try: netifaces.interface_is_up("nonexistent0") except Exception as e: print(f"Expected error: {e}") ``` -------------------------------- ### Recompile Rust code after changes Source: https://github.com/samuelyvon/netifaces-2/blob/dev/README.md After making changes to the Rust code, recompile the package by reinstalling it in editable mode. ```bash python3 -m pip install -e . ``` -------------------------------- ### InterfaceType Enum Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Provides stable, platform-independent constants for network address families, intended for use with netifaces functions. ```APIDOC ## InterfaceType Enum ### Description `InterfaceType` is an `IntEnum` providing stable, platform-independent integer values for all supported address families. Unlike the original `netifaces`, these values do **not** match the host OS's `socket` module constants. Always use `InterfaceType` (or the module-level `AF_*` aliases) rather than `socket.AF_*` when calling netifaces functions. ### Usage Use `InterfaceType` constants when accessing network interface addresses. ### Example ```python import netifaces from netifaces import InterfaceType # Preferred: use InterfaceType enum for type-safe access addrs = netifaces.ifaddresses("lo") ipv4 = addrs.get(InterfaceType.AF_INET, []) ipv6 = addrs.get(InterfaceType.AF_INET6, []) mac = addrs.get(InterfaceType.AF_LINK, []) # AF_LINK == AF_PACKET ``` ### Constants - **InterfaceType.AF_INET**: Represents IPv4 address family. - **InterfaceType.AF_INET6**: Represents IPv6 address family. - **InterfaceType.AF_LINK**: Represents link-layer address family (e.g., MAC addresses). Equivalent to `AF_PACKET` on some systems. ``` -------------------------------- ### Control Interface Name Format on Windows Source: https://context7.com/samuelyvon/netifaces-2/llms.txt Use InterfaceDisplay enum to control whether interface names are human-readable descriptions or machine-readable UUIDs on Windows. This has no effect on POSIX systems. ```python import netifaces from netifaces import InterfaceDisplay import re # Human-readable: adapter description string human_ifaces = netifaces.interfaces(InterfaceDisplay.HumanReadable) # ['Realtek PCIe GbE Family Controller', 'Intel Wi-Fi 6 AX200'] # Machine-readable: Windows UUID format '{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}' machine_ifaces = netifaces.interfaces(InterfaceDisplay.MachineReadable) uuid_pattern = r"\{[-A-F0-9]+\}" for name in machine_ifaces: assert re.fullmatch(uuid_pattern, name), f"Unexpected format: {name}" # ifaddresses() accepts either format on Windows by_index_human = netifaces.interfaces_by_index(InterfaceDisplay.HumanReadable) by_index_machine = netifaces.interfaces_by_index(InterfaceDisplay.MachineReadable) idx = next(iter(by_index_human)) human_name = by_index_human[idx] machine_name = by_index_machine[idx] # Both formats resolve to the same address data assert netifaces.ifaddresses(human_name) == netifaces.ifaddresses(machine_name) ``` -------------------------------- ### Using InterfaceType Enum for Address Families Source: https://context7.com/samuelyvon/netifaces-2/llms.txt The InterfaceType enum provides stable, platform-independent integer values for address families. Always use InterfaceType constants instead of socket module constants when calling netifaces functions for type-safe access. ```python import netifaces from netifaces import InterfaceType # Preferred: use InterfaceType enum for type-safe access addrs = netifaces.ifaddresses("lo") ipv4 = addrs.get(InterfaceType.AF_INET, []) ipv6 = addrs.get(InterfaceType.AF_INET6, []) mac = addrs.get(InterfaceType.AF_LINK, []) # AF_LINK == AF_PACKET ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.