Label takes precedence over DHCP hostname in arrival/departure alerts

iOS sends 'My iPhone' via DHCP option 12 regardless of the actual device
name set on the phone. Operator-set labels are authoritative and should
not be overridden by privacy-obscured DHCP hostnames.
This commit is contained in:
Cobra
2026-04-14 23:50:23 -04:00
parent e11cf67c55
commit f860f64a3f
+4 -5
View File
@@ -919,19 +919,18 @@ def fmt_duration(secs: float) -> str:
def format_arrival(hostname: str, ip: str, vendor: str, mac: str) -> str: def format_arrival(hostname: str, ip: str, vendor: str, mac: str) -> str:
"""Format arrival alert message. Discovered hostname takes precedence; label is fallback.""" """Format arrival alert message. Label always wins when set; hostname is fallback."""
label = device_labels.get(_normalize_mac(mac)) label = device_labels.get(_normalize_mac(mac))
# Use discovered hostname if it's real (not just the IP); fall back to label display = label or (hostname if hostname and hostname != ip else None)
display = (hostname if hostname and hostname != ip else None) or label
if display: if display:
return f"[NET] ARRIVED: {display} ({ip})" return f"[NET] ARRIVED: {display} ({ip})"
return f"[NET] ARRIVED: {ip} [{vendor}] MAC:{mac}" return f"[NET] ARRIVED: {ip} [{vendor}] MAC:{mac}"
def format_departure(hostname: str, ip: str, vendor: str, mac: str, duration: str) -> str: def format_departure(hostname: str, ip: str, vendor: str, mac: str, duration: str) -> str:
"""Format departure alert message. Discovered hostname takes precedence; label is fallback.""" """Format departure alert message. Label always wins when set; hostname is fallback."""
label = device_labels.get(_normalize_mac(mac)) label = device_labels.get(_normalize_mac(mac))
display = (hostname if hostname and hostname != ip else None) or label display = label or (hostname if hostname and hostname != ip else None)
if display: if display:
return f"[NET] DEPARTED: {display} ({ip}) — present {duration}" return f"[NET] DEPARTED: {display} ({ip}) — present {duration}"
return f"[NET] DEPARTED: {ip} [{vendor}] MAC:{mac} — present {duration}" return f"[NET] DEPARTED: {ip} [{vendor}] MAC:{mac} — present {duration}"