Laptop SSH shortcuts never point at the laptop's own address

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-21 16:31:09 -04:00
co-authored by Claude Opus 5.5
parent afd2758d87
commit b1c44fd287
+5 -1
View File
@@ -11,6 +11,7 @@ settings page (/api/fleet/hello). `config` turns that list into shortcuts: ssh n
import json
import os
import re
import subprocess
import sys
import urllib.request
@@ -48,9 +49,12 @@ def config():
# 10.66 address the laptop cannot reach (2026-10-21), and 10.6 is staff Wi-Fi.
site = lambda ip: re.match(r"10\.[1-5]\.", ip) is not None
wired = lambda ip: not ip.startswith(("10.6.", "169.254.", "127."))
# A record registered from this laptop carries the laptop's own address too (the hub adds the sender's).
own = set(re.findall(r"inet (\d+\.\d+\.\d+\.\d+)", subprocess.run(["/sbin/ifconfig"], capture_output=True, text=True).stdout))
lines, used = ["# Written by tools/fleet.py from %s/api/fleet - every machine that took this laptop's key." % HUB], set()
for m in sorted(machines, key=lambda m: m["name"].lower()):
ip = next((i for i in m["ips"] if site(i)), next((i for i in m["ips"] if wired(i)), m["ips"][0] if m["ips"] else None))
ips = [i for i in m["ips"] if i not in own]
ip = next((i for i in ips if site(i)), next((i for i in ips if wired(i)), ips[0] if ips else None))
if not ip:
continue
alias = slug(m["name"])