diff --git a/tools/fleet.py b/tools/fleet.py index b0b3fd6..3ff126a 100644 --- a/tools/fleet.py +++ b/tools/fleet.py @@ -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"])