mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
fix bad prints if no default route
This commit is contained in:
parent
9e3a560ea6
commit
836463bab2
|
@ -71,7 +71,7 @@ class TcpSrv(object):
|
||||||
def shutdown(self):
|
def shutdown(self):
|
||||||
self.log("tcpsrv", "ok bye")
|
self.log("tcpsrv", "ok bye")
|
||||||
|
|
||||||
def detect_interfaces(self, ext_ip):
|
def detect_interfaces(self, listen_ip):
|
||||||
eps = {}
|
eps = {}
|
||||||
|
|
||||||
# get all ips and their interfaces
|
# get all ips and their interfaces
|
||||||
|
@ -85,29 +85,27 @@ class TcpSrv(object):
|
||||||
for ln in ip_addr.split("\n"):
|
for ln in ip_addr.split("\n"):
|
||||||
try:
|
try:
|
||||||
ip, dev = r.match(ln.rstrip()).groups()
|
ip, dev = r.match(ln.rstrip()).groups()
|
||||||
if ext_ip in ["0.0.0.0", ip]:
|
if listen_ip in ["0.0.0.0", ip]:
|
||||||
eps[ip] = dev
|
eps[ip] = dev
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# get ip with default route
|
default_route = None
|
||||||
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
try:
|
try:
|
||||||
s.connect(("10.255.255.255", 1))
|
s.connect(("10.255.255.255", 1))
|
||||||
ip = s.getsockname()[0]
|
default_route = s.getsockname()[0]
|
||||||
except (OSError, socket.error) as ex:
|
except (OSError, socket.error) as ex:
|
||||||
if ex.errno not in [101, 10065]:
|
if ex.errno not in [101, 10065]:
|
||||||
raise
|
raise
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
if ext_ip in ["0.0.0.0", ip]:
|
if default_route and listen_ip in ["0.0.0.0", default_route]:
|
||||||
desc = "\033[32mexternal"
|
desc = "\033[32mexternal"
|
||||||
try:
|
try:
|
||||||
eps[ip] += ", " + desc
|
eps[default_route] += ", " + desc
|
||||||
except:
|
except:
|
||||||
eps[ip] = desc
|
eps[default_route] = desc
|
||||||
|
|
||||||
return eps
|
return eps
|
||||||
|
|
Loading…
Reference in a new issue