diff --git a/app.py b/app.py index 1003df1..08de864 100644 --- a/app.py +++ b/app.py @@ -186,20 +186,36 @@ def detect_ipv6(): def ping_ok(host, timeout=2): try: h = (host or "").strip() - # 去掉可能残留的 :port if h.count(":") == 1 and not h.startswith("["): h = h.split(":")[0] - import subprocess + import subprocess, socket + # ping (ICMP) r = subprocess.run(["ping", "-c", "1", "-W", str(timeout), h], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout + 2) - return r.returncode == 0 + if r.returncode == 0: + return True + # fallback: TCP connect on common ports + for port in (80, 443, 53, 22): + try: + with socket.create_connection((h, port), timeout=timeout): + return True + except Exception: + pass + return False except Exception: return False def check_tcp(host, port, timeout=5): try: - with socket.create_connection((host, port), timeout=timeout): - return True + import socket + infos = socket.getaddrinfo(host, port, type=socket.SOCK_STREAM) + for fam, typ, proto, canon, sockaddr in infos: + try: + with socket.create_connection(sockaddr, timeout=timeout): + return True + except Exception: + continue + return False except Exception: return False @@ -366,6 +382,7 @@ def run_check(): et_host = reachable[0] warn_suffix = (f" ✗ 不可达: {', '.join(unreachable)}" if unreachable else "") s.append(f"✓ 组网 {et_host} 可达" + (f" (共{len(reachable)}/{len(et_hosts)}可达)" if len(et_hosts) > 1 else "") + warn_suffix) + connected.append({"type": "easytier", "target": et_host, "domain": None}) for d in domains: if update_dns(cfg, d, et_host): connected.append({"type": "easytier", "target": et_host, "domain": d})