Spaces:
Runtime error
Runtime error
| # bot/integrations/diag_extra.py | |
| import socket | |
| from urllib.parse import urlparse | |
| def dns_check(url_or_host: str) -> str: | |
| try: | |
| v = (url_or_host or "").strip() | |
| if not v: | |
| return "ERR:empty" | |
| if "://" in v: | |
| host = urlparse(v).hostname or "" | |
| else: | |
| host = v | |
| if not host: | |
| return "ERR:no_host" | |
| infos = socket.getaddrinfo(host, 443) | |
| ips = sorted({i[4][0] for i in infos if i and i[4]}) | |
| if not ips: | |
| return "ERR:no_ips" | |
| # keep it short | |
| return "OK:" + ",".join(ips[:5]) | |
| except Exception as e: | |
| return f"ERR:{type(e).__name__}:{e}" |