Add support for multiple endpoints in ipinfo, fixes

This commit is contained in:
JeDaYoshi 2021-10-17 22:12:19 -04:00
parent 858b3dbe62
commit d8ba18a2dc
No known key found for this signature in database
GPG key ID: 8060B288C274219D

View file

@ -142,25 +142,34 @@ class Module(ModuleManager.BaseModule):
page = self._ipinfo_get(URL_IPINFO % ip).json() page = self._ipinfo_get(URL_IPINFO % ip).json()
if page: if page:
if not page.get("error", None): if page.get("error", False):
if isinstance(page["error"], (list, dict)):
event["stderr"].write(page["error"]["message"])
else:
event["stderr"].write(page["error"])
elif page.get("ip", False):
bogon = page.get("bogon", False)
hostname = page.get("hostname", None) hostname = page.get("hostname", None)
if not hostname: if not hostname and not bogon:
try: try:
hostname, alias, ips = socket.gethostbyaddr(page["ip"]) hostname, alias, ips = socket.gethostbyaddr(page["ip"])
except (socket.herror, socket.gaierror): except (socket.herror, socket.gaierror):
pass pass
data = page["ip"] data = page["ip"]
data += " (%s)" % hostname if hostname else "" if bogon:
data += " (Anycast)" if page.get("anycast", False) == True else "" data += " (Bogon)"
data += " | City: %s" % page["city"] else:
data += " | Region: %s (%s)" % (page["region"], page["country"]) data += " (%s)" % hostname if hostname else ""
data += " | ISP: %s" % page["org"] data += " (Anycast)" if page.get("anycast", False) == True else ""
data += " | Lon/Lat: %s" % page["loc"] data += " | City: %s" % page["city"]
data += " | Timezone: %s" % page["timezone"] data += " | Region: %s (%s)" % (page["region"], page["country"])
data += " | ISP: %s" % page["org"]
data += " | Lon/Lat: %s" % page["loc"]
data += " | Timezone: %s" % page["timezone"]
event["stdout"].write(data) event["stdout"].write(data)
else: else:
event["stderr"].write(page["error"]["message"]) event["stderr"].write("Unsupported endpoint")
else: else:
raise utils.EventResultsError() raise utils.EventResultsError()