mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
janus: fallback for no-gw configuration
This commit is contained in:
parent
59ed36a6af
commit
26a831d2ed
@ -98,19 +98,19 @@ class JanusRunner: # pylint: disable=too-many-instance-attributes
|
|||||||
def __get_default_ip(self) -> str:
|
def __get_default_ip(self) -> str:
|
||||||
try:
|
try:
|
||||||
gws = netifaces.gateways()
|
gws = netifaces.gateways()
|
||||||
if "default" not in gws:
|
if "default" in gws:
|
||||||
raise RuntimeError(f"No default gateway: {gws}")
|
|
||||||
|
|
||||||
iface = ""
|
|
||||||
for proto in [socket.AF_INET, socket.AF_INET6]:
|
for proto in [socket.AF_INET, socket.AF_INET6]:
|
||||||
if proto in gws["default"]:
|
if proto in gws["default"]:
|
||||||
iface = gws["default"][proto][1]
|
iface = gws["default"][proto][1]
|
||||||
break
|
addrs = netifaces.ifaddresses(iface)
|
||||||
else:
|
return addrs[proto][0]["addr"]
|
||||||
raise RuntimeError(f"No iface for the gateway {gws['default']}")
|
|
||||||
|
|
||||||
for addr in netifaces.ifaddresses(iface).get(proto, []):
|
for iface in netifaces.interfaces():
|
||||||
return addr["addr"]
|
if not iface.startswith(("lo", "docker")):
|
||||||
|
addrs = netifaces.ifaddresses(iface)
|
||||||
|
for proto in [socket.AF_INET, socket.AF_INET6]:
|
||||||
|
if proto in addrs:
|
||||||
|
return addrs[proto][0]["addr"]
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
get_logger().error("Can't get default IP: %s", tools.efmt(err))
|
get_logger().error("Can't get default IP: %s", tools.efmt(err))
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user