From 667cdd90dfb22978c26a1c87d06ef345dec1db44 Mon Sep 17 00:00:00 2001 From: ruslan Date: Wed, 6 May 2026 10:23:12 +0300 Subject: [PATCH] feat(gui): add reverse DNS hostname detection for peers Resolve hostname via PTR record on peer endpoint IP. Results cached in memory for 5 minutes to avoid latency. Hostname shown below endpoint in the peers table. Co-Authored-By: Claude Sonnet 4.6 --- gui/app.py | 23 +++++++++++++++++++++++ gui/static/style.css | 1 + gui/templates/index.html | 5 ++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gui/app.py b/gui/app.py index 538f0c1..80a73c6 100644 --- a/gui/app.py +++ b/gui/app.py @@ -197,6 +197,27 @@ def humanize_ago(ts: int, now: int) -> str: return f"{diff // 86400}д назад" +_dns_cache: dict = {} # ip -> (hostname, expires_ts) +_DNS_TTL = 300 # 5 минут + + +def resolve_hostname(ip: str) -> str: + if not ip or ip in ("-", "(none)"): + return "" + now = time.time() + if ip in _dns_cache: + host, exp = _dns_cache[ip] + if now < exp: + return host + import socket + try: + host = socket.gethostbyaddr(ip)[0] + except Exception: + host = "" + _dns_cache[ip] = (host, now + _DNS_TTL) + return host + + def next_free_ip(network: str) -> str: import ipaddress try: @@ -297,6 +318,7 @@ def index(): "routes": row.get("advertised_routes") or "-", "allowed_ips": rt.get("allowed_ips", "-"), "endpoint": rt.get("endpoint", "-"), + "hostname": resolve_hostname(rt.get("endpoint", "").split(":")[0]), "handshake_ago": humanize_ago(ts, now), "rx": bytes_h(rt.get("rx_bytes", 0)), "tx": bytes_h(rt.get("tx_bytes", 0)), @@ -337,6 +359,7 @@ def index(): "routes": imported_routes, "allowed_ips": rt.get("allowed_ips", "-"), "endpoint": rt.get("endpoint", "-"), + "hostname": resolve_hostname(rt.get("endpoint", "").split(":")[0]), "handshake_ago": humanize_ago(ts, now), "rx": bytes_h(rt.get("rx_bytes", 0)), "tx": bytes_h(rt.get("tx_bytes", 0)), diff --git a/gui/static/style.css b/gui/static/style.css index e37824f..dfc78d9 100644 --- a/gui/static/style.css +++ b/gui/static/style.css @@ -177,6 +177,7 @@ tbody tr.row-disabled td { opacity: 0.45; } .text-muted { color: var(--text-muted); } .pubkey { font-family: var(--mono); font-size: 11px; color: var(--text-muted); cursor: default; } +.hostname { font-size: 11px; color: var(--accent); font-weight: 500; } .empty { text-align: center; padding: 40px !important; color: var(--text-muted); } .empty a { color: var(--accent); text-decoration: none; } diff --git a/gui/templates/index.html b/gui/templates/index.html index 2ddbb71..1230d36 100644 --- a/gui/templates/index.html +++ b/gui/templates/index.html @@ -40,7 +40,10 @@ {{ p.client_address }} {{ p.routes }} - {{ p.endpoint }} + + {{ p.endpoint }} + {% if p.hostname %}
{{ p.hostname }}{% endif %} + ↓ {{ p.rx }} ↑ {{ p.tx }}