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
()
| 36 | |
| 37 | |
| 38 | def 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 | |
| 65 | def determine_network_status(): |
no outgoing calls
no test coverage detected