Get the first active (connected with carrier) Ethernet interface. Note: Interfaces with link-local IPs (169.254.x.x) are not considered active.
()
| 388 | |
| 389 | |
| 390 | def get_active_ethernet_interface() -> Optional[Dict]: |
| 391 | """Get the first active (connected with carrier) Ethernet interface. |
| 392 | |
| 393 | Note: Interfaces with link-local IPs (169.254.x.x) are not considered active. |
| 394 | """ |
| 395 | ethernet_interfaces = gather_ethernet_interfaces() |
| 396 | for iface in ethernet_interfaces: |
| 397 | ip_addr = iface.get('ip_address') |
| 398 | if iface.get('connected') and iface.get('has_carrier') and ip_addr and not is_link_local_ip(ip_addr): |
| 399 | return iface |
| 400 | return None |
| 401 | |
| 402 | |
| 403 | def is_ethernet_available() -> bool: |
no test coverage detected