2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
URL_GEOIP = "http://ip-api.com/json/%s"
|
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2016-03-29 11:56:58 +00:00
|
|
|
_name = "GeoIP"
|
|
|
|
|
2018-10-03 12:22:37 +00:00
|
|
|
@utils.hook("received.command.geoip", min_args=1)
|
2016-03-29 11:56:58 +00:00
|
|
|
def geoip(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Get geoip data on a given IPv4/IPv6 address
|
|
|
|
:usage: <IP>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-10-03 12:22:37 +00:00
|
|
|
page = utils.http.get_url(URL_GEOIP % event["args_split"][0],
|
2016-03-29 11:56:58 +00:00
|
|
|
json=True)
|
|
|
|
if page:
|
|
|
|
if page["status"] == "success":
|
|
|
|
data = page["query"]
|
|
|
|
data += " | Organisation: %s" % page["org"]
|
|
|
|
data += " | City: %s" % page["city"]
|
|
|
|
data += " | Region: %s (%s)" % (page["regionName"],
|
|
|
|
page["countryCode"])
|
|
|
|
data += " | ISP: %s" % page["isp"]
|
|
|
|
data += " | Lon/Lat: %s/%s" % (page["lon"],
|
|
|
|
page["lat"])
|
|
|
|
data += " | Timezone: %s" % page["timezone"]
|
|
|
|
event["stdout"].write(data)
|
|
|
|
else:
|
|
|
|
event["stderr"].write("No geoip data found")
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Failed to load results")
|