fix: use TCP socket probe instead of ping for LAN detection
Deploy Dashboard / deploy (push) Successful in 41s

This commit is contained in:
Gan, Jimmy
2026-02-26 03:27:04 +08:00
parent 1b55675201
commit 6ed57f56f5
+6 -6
View File
@@ -119,14 +119,14 @@ async def client_ip(request: Request):
ip = request.client.host ip = request.client.host
if ip.startswith("192.168.31."): if ip.startswith("192.168.31."):
return {"ip": ip, "lan": True} return {"ip": ip, "lan": True}
# Tailscale client — check if Mac is reachable on LAN
if ip.startswith("100."): if ip.startswith("100."):
import socket
try: try:
proc = await asyncio.create_subprocess_exec( s = socket.socket()
"ping", "-c", "1", "-W", "1", "192.168.31.1", s.settimeout(1)
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL, s.connect(("192.168.31.1", 80))
) s.close()
return {"ip": ip, "lan": await asyncio.wait_for(proc.wait(), 2) == 0} return {"ip": ip, "lan": True}
except Exception: except Exception:
pass pass
return {"ip": ip, "lan": False} return {"ip": ip, "lan": False}