### Example Output of ifaddr IP Enumeration Source: https://github.com/pydron/ifaddr/blob/master/docs/index.rst This is an example of the output generated by the `ifaddr.get_adapters()` function, showing IP addresses and network prefixes for various network adapters. ```none IPs of network adapter H5321 gw Mobile Broadband Driver IP ('fe80::9:ebdf:30ab:39a3', 0L, 17L)/64 IP 169.254.57.163/16 IPs of network adapter Intel(R) Centrino(R) Advanced-N 6205 IP ('fe80::481f:3c9d:c3f6:93f8', 0L, 12L)/64 IP 192.168.0.51/24 IPs of network adapter Intel(R) 82579LM Gigabit Network Connection IP ('fe80::85cd:e07e:4f7a:6aa6', 0L, 11L)/64 IP 192.168.0.53/24 IPs of network adapter Software Loopback Interface 1 IP ('::1', 0L, 0L)/128 IP 127.0.0.1/8 ``` -------------------------------- ### Get All Configured Network Adapters Source: https://context7.com/pydron/ifaddr/llms.txt Demonstrates how to use the `get_adapters` function to retrieve a list of all configured network adapters and their associated IP addresses. ```APIDOC ## get_adapters ### Description The main entry point for retrieving all network adapters and their IP addresses. Returns an iterable of `Adapter` objects representing each network interface on the system. ### Method ```python get_adapters() ``` ### Parameters None ### Request Example ```python import ifaddr # Get all configured network adapters adapters = ifaddr.get_adapters() for adapter in adapters: print(f"Adapter: {adapter.nice_name}") print(f" System name: {adapter.name}") print(f" Index: {adapter.index}") print(f" Multicast: {adapter.multicast}") for ip in adapter.ips: if ip.is_IPv4: print(f" IPv4: {ip.ip}/{ip.network_prefix}") else: # IPv6 returns (ip_string, flowinfo, scope_id) ip_addr, flowinfo, scope_id = ip.ip print(f" IPv6: {ip_addr}/{ip.network_prefix} (flowinfo={flowinfo}, scope_id={scope_id})") ``` ### Response An iterable of `Adapter` objects. #### Success Response (200) - **adapters** (list of Adapter objects) - A list containing `Adapter` objects for each network interface. #### Response Example ``` Adapter: Intel(R) Ethernet Connection System name: eth0 Index: 2 Multicast: True IPv4: 192.168.1.100/24 IPv6: fe80::1234:5678:abcd:ef01/64 (flowinfo=0, scope_id=2) Adapter: Loopback Pseudo-Interface 1 System name: lo Index: 1 Multicast: False IPv4: 127.0.0.1/8 IPv6: ::1/128 (flowinfo=0, scope_id=0) ``` ``` -------------------------------- ### Get All Adapters Including Unconfigured Source: https://context7.com/pydron/ifaddr/llms.txt Shows how to retrieve all network adapters, including those that do not have IP addresses configured, using the `include_unconfigured` parameter. ```APIDOC ## get_adapters with include_unconfigured ### Description Retrieve all network adapters including those without configured IP addresses. Useful for discovering all physical network interfaces even if they're not currently active or configured. ### Method ```python get_adapters(include_unconfigured=True) ``` ### Parameters #### Query Parameters - **include_unconfigured** (bool) - Required/Optional - If True, includes adapters without configured IP addresses. ### Request Example ```python import ifaddr # Get all adapters, including those without IP addresses adapters = ifaddr.get_adapters(include_unconfigured=True) for adapter in adapters: print(f"Adapter: {adapter.nice_name}") if adapter.ips: for ip in adapter.ips: print(f" {ip.ip}/{ip.network_prefix}") else: print(" No IP addresses configured") ``` ### Response An iterable of `Adapter` objects, potentially including those without IP addresses. #### Success Response (200) - **adapters** (list of Adapter objects) - A list containing `Adapter` objects for all network interfaces, configured or not. #### Response Example ``` Adapter: eth0 192.168.1.100/24 fe80::1234:5678:abcd:ef01/64 Adapter: eth1 No IP addresses configured Adapter: lo 127.0.0.1/8 ::1/128 ``` ``` -------------------------------- ### netifaces Compatibility Layer Source: https://context7.com/pydron/ifaddr/llms.txt Use ifaddr as a drop-in replacement for netifaces.interfaces() to get a list of all network interface names. Requires importing from ifaddr.netifaces. ```python import ifaddr.netifaces # Get list of all network interface names (equivalent to netifaces.interfaces()) interface_names = ifaddr.netifaces.interfaces() print("Network interfaces:") for name in interface_names: print(f" {name}") ``` -------------------------------- ### Get All Network Adapter IP Addresses in Python Source: https://github.com/pydron/ifaddr/blob/master/docs/index.rst Use this snippet to retrieve and print all IP addresses (IPv4 and IPv6) associated with each network adapter on the system. Ensure the `ifaddr` library is installed. ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: print ("IPs of network adapter " + adapter.nice_name) for ip in adapter.ips: print (" %s/%s" % (ip.ip, ip.network_prefix)) ``` -------------------------------- ### Get Adapters Including Unconfigured Interfaces Source: https://github.com/pydron/ifaddr/blob/master/README.rst This code snippet demonstrates how to include network interfaces that do not have any IP addresses configured. If an adapter has no IPs, it will print a message indicating so. ```python import ifaddr adapters = ifaddr.get_adapters(include_unconfigured=True) for adapter in adapters: print("IPs of network adapter " + adapter.nice_name) if adapter.ips: for ip in adapter.ips: print(" %s/%s" % (ip.ip, ip.network_prefix)) else: print(" No IPs configured") ``` -------------------------------- ### Get All Network Adapters and IPs Source: https://github.com/pydron/ifaddr/blob/master/README.rst Use this snippet to retrieve a list of all network adapters and their configured IP addresses. It iterates through each adapter and prints its name and associated IPs. ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: print("IPs of network adapter " + adapter.nice_name) for ip in adapter.ips: print(" %s/%s" % (ip.ip, ip.network_prefix)) ``` -------------------------------- ### Get All Adapters Including Unconfigured Source: https://context7.com/pydron/ifaddr/llms.txt Call `ifaddr.get_adapters(include_unconfigured=True)` to retrieve all network adapters, even those without configured IP addresses. This is useful for discovering all physical network interfaces. ```python import ifaddr # Get all adapters, including those without IP addresses adapters = ifaddr.get_adapters(include_unconfigured=True) for adapter in adapters: print(f"Adapter: {adapter.nice_name}") if adapter.ips: for ip in adapter.ips: print(f" {ip.ip}/{ip.network_prefix}") else: print(" No IP addresses configured") ``` -------------------------------- ### Get All Configured Network Adapters Source: https://context7.com/pydron/ifaddr/llms.txt Use `ifaddr.get_adapters()` to retrieve all network adapters with configured IP addresses. This function returns an iterable of `Adapter` objects, each containing details about the interface and its associated IP addresses. ```python import ifaddr # Get all configured network adapters adapters = ifaddr.get_adapters() for adapter in adapters: print(f"Adapter: {adapter.nice_name}") print(f" System name: {adapter.name}") print(f" Index: {adapter.index}") print(f" Multicast: {adapter.multicast}") for ip in adapter.ips: if ip.is_IPv4: print(f" IPv4: {ip.ip}/{ip.network_prefix}") else: # IPv6 returns (ip_string, flowinfo, scope_id) ip_addr, flowinfo, scope_id = ip.ip print(f" IPv6: {ip_addr}/{ip.network_prefix} (flowinfo={flowinfo}, scope_id={scope_id})") ``` -------------------------------- ### Adapter Class Details Source: https://context7.com/pydron/ifaddr/llms.txt Explains the structure and properties of the `Adapter` class, which represents a network interface. ```APIDOC ## Adapter Class ### Description Represents a network interface device controller (NIC). Each adapter contains a list of IP addresses and metadata about the interface including its system name, human-readable name, index, and multicast capability. ### Properties - **name** (str) - System identifier (e.g., 'eth0' on Linux, UUID on Windows). - **nice_name** (str) - Human-readable name (same as name on Linux, device name on Windows). - **ips** (list of IP objects) - A list of `IP` objects associated with this adapter. - **index** (int) - Interface index for API calls (e.g., multicast group joins). - **multicast** (bool) - Boolean indicating multicast support. ### Request Example ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: # adapter.name: System identifier (e.g., 'eth0' on Linux, UUID on Windows) # adapter.nice_name: Human-readable name (same as name on Linux, device name on Windows) # adapter.ips: List of IP objects # adapter.index: Interface index for API calls (e.g., multicast group joins) # adapter.multicast: Boolean indicating multicast support print(f"Name: {adapter.name}") print(f"Nice name: {adapter.nice_name}") print(f"Index: {adapter.index}") print(f"Multicast support: {adapter.multicast}") print(f"Number of IPs: {len(adapter.ips)}") print(repr(adapter)) # Output: Adapter(name='eth0', nice_name='eth0', ips=[...], index=2, multicast=True) ``` ### Response Example ``` Name: eth0 Nice name: eth0 Index: 2 Multicast support: True Number of IPs: 2 Adapter(name='eth0', nice_name='eth0', ips=[IP(version=4, address='192.168.1.100', network_prefix=24), IP(version=6, address='fe80::1234:5678:abcd:ef01', network_prefix=64, flowinfo=0, scope_id=2)], index=2, multicast=True) ``` ``` -------------------------------- ### Find Localhost and Specific Adapters Source: https://context7.com/pydron/ifaddr/llms.txt Search for specific IP addresses or adapters by iterating through the adapter list. Useful for finding the loopback interface or adapters with specific IP configurations. Functions `find_adapter_by_ip` and `get_non_loopback_ipv4` are defined and then called. ```python import ifaddr def find_adapter_by_ip(target_ip: str): """Find the adapter that has a specific IP address.""" adapters = ifaddr.get_adapters() for adapter in adapters: for ip in adapter.ips: if ip.is_IPv4 and ip.ip == target_ip: return adapter elif ip.is_IPv6 and ip.ip[0] == target_ip: return adapter return None def get_non_loopback_ipv4(): """Get all non-loopback IPv4 addresses.""" adapters = ifaddr.get_adapters() addresses = [] for adapter in adapters: for ip in adapter.ips: if ip.is_IPv4 and not ip.ip.startswith('127.'): addresses.append(ip.ip) return addresses # Find localhost adapter localhost_adapter = find_adapter_by_ip('127.0.0.1') if localhost_adapter: print(f"Localhost adapter: {localhost_adapter.nice_name}") # Get all external IPv4 addresses external_ips = get_non_loopback_ipv4() print(f"External IPv4 addresses: {external_ips}") ``` -------------------------------- ### Access Adapter Properties Source: https://context7.com/pydron/ifaddr/llms.txt Iterate through adapters obtained from `ifaddr.get_adapters()` to access properties like `name`, `nice_name`, `index`, `multicast`, and the list of associated `ips`. The `repr(adapter)` provides a concise string representation. ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: # adapter.name: System identifier (e.g., 'eth0' on Linux, UUID on Windows) # adapter.nice_name: Human-readable name (same as name on Linux, device name on Windows) # adapter.ips: List of IP objects # adapter.index: Interface index for API calls (e.g., multicast group joins) # adapter.multicast: Boolean indicating multicast support print(f"Name: {adapter.name}") print(f"Nice name: {adapter.nice_name}") print(f"Index: {adapter.index}") print(f"Multicast support: {adapter.multicast}") print(f"Number of IPs: {len(adapter.ips)}") print(repr(adapter)) ``` -------------------------------- ### ifaddr.get_adapters() Source: https://github.com/pydron/ifaddr/blob/master/docs/index.rst This function retrieves all network adapters and their associated IP addresses. ```APIDOC ## ifaddr.get_adapters() ### Description Receives all the network adapters with their IP addresses. ### Method Python Function Call ### Endpoint N/A (Python Library Function) ### Parameters None ### Request Example ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: print("IPs of network adapter " + adapter.nice_name) for ip in adapter.ips: print (" %s/%s" % (ip.ip, ip.network_prefix)) ``` ### Response #### Success Response - **adapters** (List[ifaddr.Adapter]) - A list of Adapter instances, each representing a network adapter. #### Response Example ```json [ { "name": "eth0", "nice_name": "Ethernet Adapter", "index": 1, "ips": [ { "ip": "192.168.1.100", "network_prefix": 24, "nice_name": "IPv4", "is_IPv4": true, "is_IPv6": false }, { "ip": "fe80::1234:5678:9abc:def0", "network_prefix": 64, "nice_name": "IPv6", "is_IPv4": false, "is_IPv6": true } ], "multicast": ["ff02::1", "ff02::2"] } ] ``` ``` -------------------------------- ### IP Class Details Source: https://context7.com/pydron/ifaddr/llms.txt Details the `IP` class, which represents an IP address associated with a network adapter, and its properties for IPv4 and IPv6. ```APIDOC ## IP Class ### Description Represents an IP address associated with a network adapter. Provides properties to distinguish between IPv4 and IPv6 addresses and access the network prefix length. ### Properties - **is_IPv4** (bool) - True if the IP address is IPv4. - **is_IPv6** (bool) - True if the IP address is IPv6. - **ip** (str or tuple) - For IPv4, this is the IP address string. For IPv6, this is a tuple `(address_string, flowinfo, scope_id)`. - **network_prefix** (int) - The network prefix length (e.g., 24 for IPv4, 64 for IPv6). - **nice_name** (str) - The human-readable name of the adapter this IP belongs to. ### Request Example ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: for ip in adapter.ips: # Check IP version if ip.is_IPv4: # IPv4: ip.ip is a string like "192.168.1.100" print(f"IPv4 Address: {ip.ip}") print(f" Network prefix: {ip.network_prefix}") print(f" Nice name: {ip.nice_name}") elif ip.is_IPv6: # IPv6: ip.ip is a tuple (address_string, flowinfo, scope_id) address, flowinfo, scope_id = ip.ip print(f"IPv6 Address: {address}") print(f" Network prefix: {ip.network_prefix}") print(f" Flow info: {flowinfo}") print(f" Scope ID: {scope_id}") print(f" Nice name: {ip.nice_name}") ``` ### Response Example ``` IPv4 Address: 192.168.1.100 Network prefix: 24 Nice name: eth0 IPv6 Address: fe80::1234:5678:abcd:ef01 Network prefix: 64 Flow info: 0 Scope ID: 2 Nice name: eth0 ``` ``` -------------------------------- ### ifaddr.Adapter Class Source: https://github.com/pydron/ifaddr/blob/master/docs/index.rst Represents a network adapter with its associated IP addresses. ```APIDOC ## ifaddr.Adapter Class ### Description Represents a network adapter, containing its name, index, and a list of IP addresses. ### Members - **name** (string) - The system name of the network adapter. - **ips** (List[ifaddr.IP]) - A list of IP address objects associated with this adapter. - **nice_name** (string) - A human-readable name for the network adapter. - **index** (integer) - The index of the network adapter. - **multicast** (List[string]) - A list of multicast addresses associated with the adapter. ``` -------------------------------- ### Filter IPv4 and IPv6 Addresses Source: https://context7.com/pydron/ifaddr/llms.txt Retrieve all IPv4 or IPv6 addresses from network adapters. Requires the ifaddr library to be imported. ```python import ifaddr adapters = ifaddr.get_adapters() # Get all IPv4 addresses ipv4_addresses = [] for adapter in adapters: for ip in adapter.ips: if ip.is_IPv4: ipv4_addresses.append({ 'adapter': adapter.nice_name, 'ip': ip.ip, 'prefix': ip.network_prefix }) print("IPv4 Addresses:") for addr in ipv4_addresses: print(f" {addr['adapter']}: {addr['ip']}/{addr['prefix']}") # Get all IPv6 addresses ipv6_addresses = [] for adapter in adapters: for ip in adapter.ips: if ip.is_IPv6: address, flowinfo, scope_id = ip.ip ipv6_addresses.append({ 'adapter': adapter.nice_name, 'ip': address, 'prefix': ip.network_prefix, 'scope_id': scope_id }) print("\nIPv6 Addresses:") for addr in ipv6_addresses: print(f" {addr['adapter']}: {addr['ip']}/{addr['prefix']} (scope={addr['scope_id']})") ``` -------------------------------- ### Access IP Address Properties Source: https://context7.com/pydron/ifaddr/llms.txt Iterate through the `ips` list of an `Adapter` object to access IP address details. Use `ip.is_IPv4` to distinguish between IPv4 and IPv6. For IPv4, `ip.ip` is a string; for IPv6, it's a tuple containing the address string, flowinfo, and scope_id. ```python import ifaddr adapters = ifaddr.get_adapters() for adapter in adapters: for ip in adapter.ips: # Check IP version if ip.is_IPv4: # IPv4: ip.ip is a string like "192.168.1.100" print(f"IPv4 Address: {ip.ip}") print(f" Network prefix: {ip.network_prefix}") print(f" Nice name: {ip.nice_name}") elif ip.is_IPv6: # IPv6: ip.ip is a tuple (address_string, flowinfo, scope_id) address, flowinfo, scope_id = ip.ip print(f"IPv6 Address: {address}") print(f" Network prefix: {ip.network_prefix}") print(f" Flow info: {flowinfo}") print(f" Scope ID: {scope_id}") print(f" Nice name: {ip.nice_name}") ``` -------------------------------- ### ifaddr.IP Class Source: https://github.com/pydron/ifaddr/blob/master/docs/index.rst Represents an IP address associated with a network adapter. ```APIDOC ## ifaddr.IP Class ### Description Represents an IP address, including its network prefix and type. ### Members - **ip** (string) - The IP address string. - **network_prefix** (integer) - The network prefix length (e.g., 24 for /24). - **nice_name** (string) - A human-readable name for the IP address type (e.g., 'IPv4', 'IPv6'). - **is_IPv4** (boolean) - True if the address is an IPv4 address, False otherwise. - **is_IPv6** (boolean) - True if the address is an IPv6 address, False otherwise. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.