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
if ip.startswith("192.168.31."):
return {"ip": ip, "lan": True}
# Tailscale client — check if Mac is reachable on LAN
if ip.startswith("100."):
import socket
try:
proc = await asyncio.create_subprocess_exec(
"ping", "-c", "1", "-W", "1", "192.168.31.1",
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL,
)
return {"ip": ip, "lan": await asyncio.wait_for(proc.wait(), 2) == 0}
s = socket.socket()
s.settimeout(1)
s.connect(("192.168.31.1", 80))
s.close()
return {"ip": ip, "lan": True}
except Exception:
pass
return {"ip": ip, "lan": False}