diff --git a/app/app.py b/app/app.py index 48811c4..f5c6bda 100644 --- a/app/app.py +++ b/app/app.py @@ -722,7 +722,7 @@ def _lookup_ip_asn(ip: str) -> dict: except Exception: pass - # Fallback : ipinfo.io si toujours pas d'AS + # Fallback 1 : ipinfo.io if not result.get("asn"): try: req = urllib.request.Request( @@ -736,6 +736,29 @@ def _lookup_ip_asn(ip: str) -> dict: except Exception: pass + # Fallback 2 : Team Cymru whois (port 43, TCP — fonctionne même si HTTPS bloqué) + if not result.get("asn"): + try: + import socket as _socket + s = _socket.create_connection(("whois.cymru.com", 43), timeout=8) + s.sendall(f"verbose\n{ip}\n".encode()) + data = b"" + while True: + chunk = s.recv(4096) + if not chunk: + break + data += chunk + s.close() + for line in data.decode(errors="replace").splitlines(): + if "|" not in line or line.startswith("AS"): + continue + parts = [p.strip() for p in line.split("|")] + if len(parts) >= 7 and parts[0] not in ("", "NA"): + result = {"asn": parts[0], "name": parts[6], "country": parts[3]} + break + except Exception: + pass + # Mise en cache seulement si on a trouvé un AS if result.get("asn"): with _pg() as conn: