additional fixes to ipinfo/geoip

This commit is contained in:
JeDaYoshi 2021-10-18 18:18:05 -04:00
parent d8ba18a2dc
commit 24e073313c
No known key found for this signature in database
GPG key ID: 8060B288C274219D

View file

@ -30,7 +30,6 @@ class Module(ModuleManager.BaseModule):
ip = line.match ip = line.match
if not ip: if not ip:
raise utils.EventError("No IP provided") raise utils.EventError("No IP provided")
return ip return ip
def _ipinfo_get(self, url): def _ipinfo_get(self, url):
@ -111,6 +110,7 @@ class Module(ModuleManager.BaseModule):
page = utils.http.request(URL_GEOIP % ip).json() page = utils.http.request(URL_GEOIP % ip).json()
if page: if page:
if page["status"] == "success": if page["status"] == "success":
hostname = None
try: try:
hostname, alias, ips = socket.gethostbyaddr(page["query"]) hostname, alias, ips = socket.gethostbyaddr(page["query"])
except (socket.herror, socket.gaierror): except (socket.herror, socket.gaierror):
@ -156,17 +156,18 @@ class Module(ModuleManager.BaseModule):
except (socket.herror, socket.gaierror): except (socket.herror, socket.gaierror):
pass pass
data = page["ip"] data = page["ip"]
if bogon: if bogon:
data += " (Bogon)" data += " (Bogon)"
else: else:
data += " (%s)" % hostname if hostname else "" data += " (%s)" % hostname if hostname else ""
data += " (Anycast)" if page.get("anycast", False) == True else "" data += " (Anycast)" if page.get("anycast", False) == True else ""
data += " | City: %s" % page["city"] if page.get("country", False):
data += " | Region: %s (%s)" % (page["region"], page["country"]) data += " | City: %s" % page["city"]
data += " | ISP: %s" % page["org"] data += " | Region: %s (%s)" % (page["region"], page["country"])
data += " | Lon/Lat: %s" % page["loc"] data += " | ISP: %s" % page.get("org", "Unknown")
data += " | Timezone: %s" % page["timezone"] data += " | Lon/Lat: %s" % page["loc"]
data += " | Timezone: %s" % page["timezone"]
event["stdout"].write(data) event["stdout"].write(data)
else: else:
event["stderr"].write("Unsupported endpoint") event["stderr"].write("Unsupported endpoint")