Files
zima-apps/Apps/docker-ip-addr-manager/backend/app/interfaces.py
T
2026-03-18 21:43:59 +01:00

29 lines
731 B
Python

from __future__ import annotations
import subprocess
def list_host_interfaces() -> list[str]:
result = subprocess.run(
["ip", "-o", "link", "show"],
capture_output=True,
text=True,
check=False,
)
if result.returncode != 0:
raise RuntimeError(f"Failed to list interfaces: {result.stderr.strip()}")
interfaces: list[str] = []
seen = set()
for line in result.stdout.splitlines():
parts = line.split(":", maxsplit=2)
if len(parts) < 2:
continue
name = parts[1].strip().split("@", maxsplit=1)[0]
if not name or name in seen:
continue
seen.add(name)
interfaces.append(name)
return interfaces