MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / get_preferred_scan_interface

Function get_preferred_scan_interface

webapp_modern.py:11410–11427  ·  view source on GitHub ↗

Get the preferred interface for network scanning (Ethernet or WiFi).

()

Source from the content-addressed store, hash-verified

11408 try:
11409 result = subprocess.run(
11410 ['ip', '-o', '-4', 'addr', 'show'],
11411 capture_output=True, text=True, timeout=5)
11412 if result.returncode != 0:
11413 return None
11414 except Exception:
11415 return None
11416 import ipaddress as _ipaddress
11417 for line in result.stdout.strip().splitlines():
11418 parts = line.split()
11419 if len(parts) < 4:
11420 continue
11421 if candidates and parts[1] not in candidates:
11422 continue
11423 for i, p in enumerate(parts):
11424 if p == 'inet' and i + 1 < len(parts):
11425 cidr = parts[i + 1]
11426 if cidr.startswith('127.'):
11427 continue
11428 try:
11429 return str(_ipaddress.IPv4Network(cidr, strict=False))
11430 except (ValueError, _ipaddress.NetmaskValueError):

Callers

nothing calls this directly

Calls 6

refresh_from_systemMethod · 0.80
get_ethernet_statusMethod · 0.80
errorMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected