2018-09-24 14:13:27 +00:00
|
|
|
from src import Utils
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
URL_GEOIP = "http://ip-api.com/json/%s"
|
|
|
|
|
|
|
|
class Module(object):
|
|
|
|
_name = "GeoIP"
|
2018-09-02 18:54:45 +00:00
|
|
|
def __init__(self, bot, events, exports):
|
2018-09-19 12:25:12 +00:00
|
|
|
events.on("received.command.geoip").hook(self.geoip, min_args=1,
|
|
|
|
help="Get geoip data on a given IPv4/IPv6 address", usage="<IP>")
|
2016-03-29 11:56:58 +00:00
|
|
|
|
|
|
|
def geoip(self, event):
|
|
|
|
page = Utils.get_url(URL_GEOIP % event["args_split"][0],
|
|
|
|
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")
|