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:
+5
-1
@@ -11,6 +11,7 @@ settings page (/api/fleet/hello). `config` turns that list into shortcuts: ssh n
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import urllib.request
|
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.
|
# 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
|
site = lambda ip: re.match(r"10\.[1-5]\.", ip) is not None
|
||||||
wired = lambda ip: not ip.startswith(("10.6.", "169.254.", "127."))
|
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()
|
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()):
|
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:
|
if not ip:
|
||||||
continue
|
continue
|
||||||
alias = slug(m["name"])
|
alias = slug(m["name"])
|
||||||
|
|||||||
Reference in New Issue
Block a user