diff --git a/app.py b/app.py index 82b7d7b..e67b8c0 100644 --- a/app.py +++ b/app.py @@ -332,42 +332,42 @@ import ipaddress as _ipaddress _wg_managed_subnets: list = [] # beim Connect gemerkte Subnetze für sauberes Cleanup -def _local_subnets() -> list: - """Alle direkt verbundenen IPv4-Subnetze außer WireGuard-Interface und Loopback.""" - r = subprocess.run(['ip', '-4', 'route', 'show', 'table', 'main'], - capture_output=True, text=True) +def _local_subnets_before_vpn() -> list: + """Subnetze aller lokalen Interfaces (außer Loopback) via 'ip addr show'. + Muss VOR wg-quick up aufgerufen werden, damit wg-quick die Tabelle noch + nicht verändert hat.""" + r = subprocess.run(['ip', '-4', 'addr', 'show'], capture_output=True, text=True) seen, result = set(), [] + current_iface = '' for line in r.stdout.splitlines(): - parts = line.split() - if not parts or parts[0] in ('default', 'unreachable', 'prohibit'): - continue - if 'dev' not in parts: - continue - dev = parts[parts.index('dev') + 1] - if dev == WG_IFACE: - continue - try: - net = str(_ipaddress.IPv4Network(parts[0], strict=False)) - if net not in seen and not _ipaddress.IPv4Network(net).is_loopback: - seen.add(net) - result.append(net) - except ValueError: - pass + if not line[:1].isspace(): + # Zeile wie "2: wlan0: