Spaces:
Runtime error
Runtime error
Create diag_extra.py
Browse files
bot/integrations/diag_extra.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# PATH: bot/integrations/diag_extra.py
|
| 2 |
+
import socket
|
| 3 |
+
from urllib.parse import urlparse
|
| 4 |
+
|
| 5 |
+
def dns_check(url: str) -> str:
|
| 6 |
+
try:
|
| 7 |
+
host = urlparse(url).hostname
|
| 8 |
+
if not host:
|
| 9 |
+
return "bad_url"
|
| 10 |
+
infos = socket.getaddrinfo(host, 443, type=socket.SOCK_STREAM)
|
| 11 |
+
ips = sorted({i[4][0] for i in infos})
|
| 12 |
+
return "OK " + ", ".join(ips[:6])
|
| 13 |
+
except Exception as e:
|
| 14 |
+
return f"ERR:{type(e).__name__}:{e}"
|