Diagnose a target URL before scanning - check accessibility, DNS, connectivity
()
| 18352 | added += 1 |
| 18353 | if added: |
| 18354 | logger.debug(f"Neighbour table added {added} host(s) the ARP sweep missed") |
| 18355 | except Exception as e: # noqa: BLE001 |
| 18356 | logger.debug(f"Could not merge neighbour table: {e}") |
| 18357 | |
| 18358 | return hosts |
| 18359 | |
| 18360 | def _detect_local_cidr(): |
| 18361 | """Return the local network CIDR derived from `ip` output, or None. |
| 18362 | |
| 18363 | Used as a runtime fallback when an API caller doesn't pass an explicit |
| 18364 | network=. Replaces the old hardcoded '192.168.1.0/24' default that |
| 18365 | silently scanned the wrong subnet on any non-192.168.1.x network. |
| 18366 | """ |
| 18367 | try: |
| 18368 | # Prefer the interface that actually carries the LAN (wired or |
| 18369 | # wireless); a wired-only box has no Wi-Fi interface to key off. |
| 18370 | iface = _get_lan_iface() |
| 18371 | except Exception: |
| 18372 | iface = None |
| 18373 | candidates = [iface] if iface else [] |
| 18374 | try: |
| 18375 | result = subprocess.run( |
| 18376 | ['ip', '-o', '-4', 'addr', 'show'], |
| 18377 | capture_output=True, text=True, timeout=5) |
| 18378 | if result.returncode != 0: |
| 18379 | return None |
| 18380 | except Exception: |
| 18381 | return None |
| 18382 | import ipaddress as _ipaddress |
| 18383 | for line in result.stdout.strip().splitlines(): |
| 18384 | parts = line.split() |
| 18385 | if len(parts) < 4: |
| 18386 | continue |
| 18387 | if candidates and parts[1] not in candidates: |
| 18388 | continue |
| 18389 | for i, p in enumerate(parts): |
| 18390 | if p == 'inet' and i + 1 < len(parts): |
| 18391 | cidr = parts[i + 1] |
nothing calls this directly
no test coverage detected