From 24e073313c1fdeb52df6a79d1dd6223aa9c792f7 Mon Sep 17 00:00:00 2001 From: JeDaYoshi Date: Mon, 18 Oct 2021 18:18:05 -0400 Subject: [PATCH] additional fixes to ipinfo/geoip --- modules/ip_addresses.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/ip_addresses.py b/modules/ip_addresses.py index 1102b64d..09d46b5b 100644 --- a/modules/ip_addresses.py +++ b/modules/ip_addresses.py @@ -30,7 +30,6 @@ class Module(ModuleManager.BaseModule): ip = line.match if not ip: raise utils.EventError("No IP provided") - return ip def _ipinfo_get(self, url): @@ -111,6 +110,7 @@ class Module(ModuleManager.BaseModule): page = utils.http.request(URL_GEOIP % ip).json() if page: if page["status"] == "success": + hostname = None try: hostname, alias, ips = socket.gethostbyaddr(page["query"]) except (socket.herror, socket.gaierror): @@ -156,17 +156,18 @@ class Module(ModuleManager.BaseModule): except (socket.herror, socket.gaierror): pass - data = page["ip"] + data = page["ip"] if bogon: data += " (Bogon)" else: data += " (%s)" % hostname if hostname else "" data += " (Anycast)" if page.get("anycast", False) == True else "" - data += " | City: %s" % page["city"] - data += " | Region: %s (%s)" % (page["region"], page["country"]) - data += " | ISP: %s" % page["org"] - data += " | Lon/Lat: %s" % page["loc"] - data += " | Timezone: %s" % page["timezone"] + if page.get("country", False): + data += " | City: %s" % page["city"] + data += " | Region: %s (%s)" % (page["region"], page["country"]) + data += " | ISP: %s" % page.get("org", "Unknown") + data += " | Lon/Lat: %s" % page["loc"] + data += " | Timezone: %s" % page["timezone"] event["stdout"].write(data) else: event["stderr"].write("Unsupported endpoint")