MCPcopy Create free account
hub / github.com/tiny-pilot/tinypilot / get_network_interfaces

Function get_network_interfaces

app/network.py:38–62  ·  view source on GitHub ↗

Get a list of physical network interface names. Excludes loopback and virtual interfaces. A device is considered "physical" if /sys/class/net/ /device exists (i.e., it’s backed by hardware). Returns: A list of interface names for all available physical network interfaces

()

Source from the content-addressed store, hash-verified

36
37
38def get_network_interfaces():
39 """Get a list of physical network interface names.
40
41 Excludes loopback and virtual interfaces. A device is considered "physical"
42 if /sys/class/net/<ifname>/device exists (i.e., it’s backed by hardware).
43
44 Returns:
45 A list of interface names for all available physical network interfaces.
46 """
47 sys_net_path = Path(_INTERFACES_DIR)
48 if not sys_net_path.is_dir():
49 logger.debug('%s is not available', str(_INTERFACES_DIR))
50 return []
51
52 interface_names = []
53 for iface_path in sys_net_path.iterdir():
54 # We know we don't want the loopback interface.
55 if iface_path.name == 'lo':
56 continue
57 # If /sys/class/net/<ifname>/device exists, the interface appears
58 # to be hardware.
59 if (iface_path / 'device').exists():
60 interface_names.append(iface_path.name)
61
62 return sorted(interface_names)
63
64
65def determine_network_status():

Callers 1

determine_network_statusFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected