Add support for multiple endpoints in ipinfo, fixes
This commit is contained in:
parent
858b3dbe62
commit
d8ba18a2dc
1 changed files with 19 additions and 10 deletions
|
@ -142,15 +142,24 @@ class Module(ModuleManager.BaseModule):
|
|||
|
||||
page = self._ipinfo_get(URL_IPINFO % ip).json()
|
||||
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)
|
||||
if not hostname:
|
||||
if not hostname and not bogon:
|
||||
try:
|
||||
hostname, alias, ips = socket.gethostbyaddr(page["ip"])
|
||||
except (socket.herror, socket.gaierror):
|
||||
pass
|
||||
|
||||
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"]
|
||||
|
@ -160,7 +169,7 @@ class Module(ModuleManager.BaseModule):
|
|||
data += " | Timezone: %s" % page["timezone"]
|
||||
event["stdout"].write(data)
|
||||
else:
|
||||
event["stderr"].write(page["error"]["message"])
|
||||
event["stderr"].write("Unsupported endpoint")
|
||||
else:
|
||||
raise utils.EventResultsError()
|
||||
|
||||
|
|
Loading…
Reference in a new issue