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()
|
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"]
|
||||||
|
if bogon:
|
||||||
|
data += " (Bogon)"
|
||||||
|
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"]
|
data += " | City: %s" % page["city"]
|
||||||
|
@ -160,7 +169,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
data += " | Timezone: %s" % page["timezone"]
|
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()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue