From 81b5a0fae204d1448cd7a908676a71306dcb7b14 Mon Sep 17 00:00:00 2001 From: Alpinux Date: Wed, 6 May 2026 19:03:55 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20:=20fallbacks=20ASN=20=E2=80=94=20Cymru?= =?UTF-8?q?=20avant=20ipinfo.io=20(HTTPS=20bloqu=C3=A9=20serveur)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ip-api.com → Team Cymru whois (TCP 43) → ipinfo.io (timeout 2s). Évite 5s de blocage par IP quand HTTPS sortant est filtré. Co-Authored-By: Claude Sonnet 4.6 --- app/app.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/app.py b/app/app.py index f5c6bda..f4b5a71 100644 --- a/app/app.py +++ b/app/app.py @@ -722,21 +722,7 @@ def _lookup_ip_asn(ip: str) -> dict: except Exception: pass - # Fallback 1 : ipinfo.io - if not result.get("asn"): - try: - req = urllib.request.Request( - f"https://ipinfo.io/{ip}/json", - headers={"User-Agent": "alpinux-static/1.0", "Accept": "application/json"}) - with urllib.request.urlopen(req, timeout=5) as resp: - d = json.loads(resp.read()) - org = d.get("org", "") - if org: - result = _parse_as_field(org, d.get("country", "")) - except Exception: - pass - - # Fallback 2 : Team Cymru whois (port 43, TCP — fonctionne même si HTTPS bloqué) + # Fallback 1 : Team Cymru whois (TCP port 43 — fonctionne même si HTTPS sortant bloqué) if not result.get("asn"): try: import socket as _socket @@ -759,6 +745,20 @@ def _lookup_ip_asn(ip: str) -> dict: except Exception: pass + # Fallback 2 : ipinfo.io (HTTPS — peut être bloqué côté serveur, timeout court) + if not result.get("asn"): + try: + req = urllib.request.Request( + f"https://ipinfo.io/{ip}/json", + headers={"User-Agent": "alpinux-static/1.0", "Accept": "application/json"}) + with urllib.request.urlopen(req, timeout=2) as resp: + d = json.loads(resp.read()) + org = d.get("org", "") + if org: + result = _parse_as_field(org, d.get("country", "")) + except Exception: + pass + # Mise en cache seulement si on a trouvé un AS if result.get("asn"): with _pg() as conn: