feat: LAN detection via ping probe for Tailscale clients at home
Deploy Dashboard / deploy (push) Successful in 1m16s

This commit is contained in:
Gan, Jimmy
2026-02-26 03:19:14 +08:00
parent 2835e6b021
commit da1f709f01
2 changed files with 15 additions and 2 deletions
+14 -1
View File
@@ -116,7 +116,20 @@ async def health():
@app.get("/api/client-ip")
async def client_ip(request: Request):
return {"ip": request.client.host}
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."):
try:
proc = await asyncio.create_subprocess_exec(
"ping", "-c", "1", "-W", "1", "192.168.31.2",
stdout=asyncio.subprocess.DEVNULL, stderr=asyncio.subprocess.DEVNULL,
)
return {"ip": ip, "lan": await asyncio.wait_for(proc.wait(), 2) == 0}
except Exception:
pass
return {"ip": ip, "lan": False}
# Public auth endpoints
app.include_router(auth.router, prefix="/api/auth", tags=["auth"])