Spaces:
Runtime error
Runtime error
Update bot/integrations/diag_extra.py
Browse files
bot/integrations/diag_extra.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
#
|
| 2 |
import socket
|
| 3 |
from urllib.parse import urlparse
|
| 4 |
|
|
@@ -7,20 +7,20 @@ def dns_check(url_or_host: str) -> str:
|
|
| 7 |
v = (url_or_host or "").strip()
|
| 8 |
if not v:
|
| 9 |
return "ERR:empty"
|
|
|
|
| 10 |
if "://" in v:
|
| 11 |
host = urlparse(v).hostname or ""
|
| 12 |
else:
|
| 13 |
host = v
|
|
|
|
| 14 |
if not host:
|
| 15 |
return "ERR:no_host"
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
for i in infos
|
| 19 |
-
ip = i[4][0]
|
| 20 |
-
if ip not in ips:
|
| 21 |
-
ips.append(ip)
|
| 22 |
if not ips:
|
| 23 |
return "ERR:no_ips"
|
| 24 |
-
|
|
|
|
| 25 |
except Exception as e:
|
| 26 |
return f"ERR:{type(e).__name__}:{e}"
|
|
|
|
| 1 |
+
# bot/integrations/diag_extra.py
|
| 2 |
import socket
|
| 3 |
from urllib.parse import urlparse
|
| 4 |
|
|
|
|
| 7 |
v = (url_or_host or "").strip()
|
| 8 |
if not v:
|
| 9 |
return "ERR:empty"
|
| 10 |
+
|
| 11 |
if "://" in v:
|
| 12 |
host = urlparse(v).hostname or ""
|
| 13 |
else:
|
| 14 |
host = v
|
| 15 |
+
|
| 16 |
if not host:
|
| 17 |
return "ERR:no_host"
|
| 18 |
+
|
| 19 |
+
infos = socket.getaddrinfo(host, 443)
|
| 20 |
+
ips = sorted({i[4][0] for i in infos if i and i[4]})
|
|
|
|
|
|
|
|
|
|
| 21 |
if not ips:
|
| 22 |
return "ERR:no_ips"
|
| 23 |
+
# keep it short
|
| 24 |
+
return "OK:" + ",".join(ips[:5])
|
| 25 |
except Exception as e:
|
| 26 |
return f"ERR:{type(e).__name__}:{e}"
|