From 291c9756623c971f9dc94c81493d76d4360b957b Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Mon, 3 May 2021 09:28:30 +0200 Subject: [PATCH] Add handler for unknown IPs --- src/info.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/info.php b/src/info.php index 115029a..895849a 100644 --- a/src/info.php +++ b/src/info.php @@ -11,7 +11,7 @@ $hostname = gethostbyaddr($ip); $res = array(); $res["address"] = $ip; if ($ip !== $hostname){ - $res["hostname"] = $hostname; + $res["hostname"] = $hostname; } $countrydb = '/var/lib/GeoIP/GeoLite2-Country.mmdb'; $asndb = '/var/lib/GeoIP/GeoLite2-ASN.mmdb'; @@ -21,5 +21,12 @@ $asnr = (new Reader($asndb))->get($ip); $res["country"] = (new Reader($countrydb))->get($ip)["country"]["iso_code"]; $res["asn"] = "AS".$asnr["autonomous_system_number"]." ".$asnr["autonomous_system_organization"]; +if ($res["country"] == null) { + $res["country"] = "_unknown"; +} + +if ($asnr["autonomous_system_number"] == null) { + $res["asn"] = "No GeoIP entry found, are you new?"; +} print(json_encode($res));