From ab937f02bae10e3caba8125b7d005cd704023e9d Mon Sep 17 00:00:00 2001 From: 3970260761 <3970260761@qq.com> Date: Mon, 9 Nov 2026 10:23:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=9E=E9=80=9A=E6=80=A7=E6=A3=80?= =?UTF-8?q?=E6=B5=8B=E6=94=AF=E6=8C=81TCP=E5=9B=9E=E9=80=80=E4=B8=8E?= =?UTF-8?q?=E5=A4=9AIP=E8=A7=A3=E6=9E=90;=20=E7=8A=B6=E6=80=81=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=BD=93=E5=89=8D=E4=BD=BF=E7=94=A8=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.py | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) 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})