mirror of
https://github.com/9001/copyparty.git
synced 2025-08-18 09:22:31 -06:00
include all IPs + link status in server url listing
This commit is contained in:
parent
c9c4aac6cf
commit
04592a98d2
|
@ -57,13 +57,19 @@ class TcpSrv(object):
|
||||||
msgs = []
|
msgs = []
|
||||||
title_tab = {}
|
title_tab = {}
|
||||||
title_vars = [x[1:] for x in self.args.wintitle.split(" ") if x.startswith("$")]
|
title_vars = [x[1:] for x in self.args.wintitle.split(" ") if x.startswith("$")]
|
||||||
m = "available @ http://{}:{}/ (\033[33m{}\033[0m)"
|
m = "available @ {}://{}:{}/ (\033[33m{}\033[0m)"
|
||||||
for ip, desc in sorted(eps.items(), key=lambda x: x[1]):
|
for ip, desc in sorted(eps.items(), key=lambda x: x[1]):
|
||||||
for port in sorted(self.args.p):
|
for port in sorted(self.args.p):
|
||||||
if port not in ok.get(ip, ok.get("0.0.0.0", [])):
|
if port not in ok.get(ip, ok.get("0.0.0.0", [])):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
msgs.append(m.format(ip, port, desc))
|
proto = " http"
|
||||||
|
if self.args.http_only:
|
||||||
|
pass
|
||||||
|
elif self.args.https_only or port == 443:
|
||||||
|
proto = "https"
|
||||||
|
|
||||||
|
msgs.append(m.format(proto, ip, port, desc))
|
||||||
|
|
||||||
if not self.args.wintitle:
|
if not self.args.wintitle:
|
||||||
continue
|
continue
|
||||||
|
@ -144,10 +150,15 @@ class TcpSrv(object):
|
||||||
return eps
|
return eps
|
||||||
|
|
||||||
r = re.compile(r"^\s+inet ([^ ]+)/.* (.*)")
|
r = re.compile(r"^\s+inet ([^ ]+)/.* (.*)")
|
||||||
|
ri = re.compile(r"^\s*[0-9]+\s*:.*")
|
||||||
|
up = False
|
||||||
for ln in txt.split("\n"):
|
for ln in txt.split("\n"):
|
||||||
|
if ri.match(ln):
|
||||||
|
up = "UP" in re.split("[>,< ]", ln)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ip, dev = r.match(ln.rstrip()).groups()
|
ip, dev = r.match(ln.rstrip()).groups()
|
||||||
eps[ip] = dev
|
eps[ip] = dev + ("" if up else ", \033[31mLINK-DOWN")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -177,6 +188,7 @@ class TcpSrv(object):
|
||||||
|
|
||||||
def ips_windows_ipconfig(self):
|
def ips_windows_ipconfig(self):
|
||||||
eps = {}
|
eps = {}
|
||||||
|
offs = {}
|
||||||
try:
|
try:
|
||||||
txt, _ = chkcmd(["ipconfig"])
|
txt, _ = chkcmd(["ipconfig"])
|
||||||
except:
|
except:
|
||||||
|
@ -184,18 +196,29 @@ class TcpSrv(object):
|
||||||
|
|
||||||
rdev = re.compile(r"(^[^ ].*):$")
|
rdev = re.compile(r"(^[^ ].*):$")
|
||||||
rip = re.compile(r"^ +IPv?4? [^:]+: *([0-9\.]{7,15})$")
|
rip = re.compile(r"^ +IPv?4? [^:]+: *([0-9\.]{7,15})$")
|
||||||
|
roff = re.compile(r".*: Media disconnected$")
|
||||||
dev = None
|
dev = None
|
||||||
for ln in txt.replace("\r", "").split("\n"):
|
for ln in txt.replace("\r", "").split("\n"):
|
||||||
m = rdev.match(ln)
|
m = rdev.match(ln)
|
||||||
if m:
|
if m:
|
||||||
|
if dev and dev not in eps.values():
|
||||||
|
offs[dev] = 1
|
||||||
|
|
||||||
dev = m.group(1).split(" adapter ", 1)[-1]
|
dev = m.group(1).split(" adapter ", 1)[-1]
|
||||||
|
|
||||||
|
if dev and roff.match(ln):
|
||||||
|
offs[dev] = 1
|
||||||
|
dev = None
|
||||||
|
|
||||||
m = rip.match(ln)
|
m = rip.match(ln)
|
||||||
if m and dev:
|
if m and dev:
|
||||||
eps[m.group(1)] = dev
|
eps[m.group(1)] = dev
|
||||||
dev = None
|
dev = None
|
||||||
|
|
||||||
return eps
|
if dev and dev not in eps.values():
|
||||||
|
offs[dev] = 1
|
||||||
|
|
||||||
|
return eps, offs
|
||||||
|
|
||||||
def ips_windows_netsh(self):
|
def ips_windows_netsh(self):
|
||||||
eps = {}
|
eps = {}
|
||||||
|
@ -215,7 +238,6 @@ class TcpSrv(object):
|
||||||
m = rip.match(ln)
|
m = rip.match(ln)
|
||||||
if m and dev:
|
if m and dev:
|
||||||
eps[m.group(1)] = dev
|
eps[m.group(1)] = dev
|
||||||
dev = None
|
|
||||||
|
|
||||||
return eps
|
return eps
|
||||||
|
|
||||||
|
@ -223,8 +245,11 @@ class TcpSrv(object):
|
||||||
if MACOS:
|
if MACOS:
|
||||||
eps = self.ips_macos()
|
eps = self.ips_macos()
|
||||||
elif ANYWIN:
|
elif ANYWIN:
|
||||||
eps = self.ips_windows_ipconfig() # sees more interfaces
|
eps, off = self.ips_windows_ipconfig() # sees more interfaces + link state
|
||||||
eps.update(self.ips_windows_netsh()) # has better names
|
eps.update(self.ips_windows_netsh()) # has better names
|
||||||
|
for k, v in eps.items():
|
||||||
|
if v in off:
|
||||||
|
eps[k] += ", \033[31mLINK-DOWN"
|
||||||
else:
|
else:
|
||||||
eps = self.ips_linux()
|
eps = self.ips_linux()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue