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:
@@ -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}"
|
||||||
|
|||||||
Reference in New Issue
Block a user