Lookup IP address ISP info

This commit is contained in:
JonnyWong16 2016-07-31 11:10:26 -07:00
parent 469d22a833
commit aba39d06bf
4 changed files with 68 additions and 3 deletions

View file

@ -20,6 +20,8 @@ import geoip2.database, geoip2.errors
import gzip
import hashlib
import imghdr
from ipwhois import IPWhois
from ipwhois.utils import get_countries
from IPy import IP
import json
import math
@ -616,6 +618,17 @@ def geoip_lookup(ip_address):
except Exception as e:
return 'Error: %s' % e
nets = []
try:
whois = IPWhois(ip_address).lookup_whois()
countries = get_countries()
nets = whois['nets']
for net in nets:
net['country'] = countries[net['country']]
net['postal_code'] = net['postal_code'].replace('-', ' ')
except Exception as e:
logger.warn(u"PlexPy Helpers :: %s." % e)
geo_info = {'continent': geo.continent.name,
'country': geo.country.name,
'region': geo.subdivisions.most_specific.name,
@ -624,7 +637,8 @@ def geoip_lookup(ip_address):
'timezone': geo.location.time_zone,
'latitude': geo.location.latitude,
'longitude': geo.location.longitude,
'accuracy': geo.location.accuracy_radius
'accuracy': geo.location.accuracy_radius,
'nets': nets
}
return geo_info

View file

@ -4310,7 +4310,18 @@ class WebInterface(object):
"timezone": "America/Los_Angeles",
"latitude": 37.386,
"longitude": -122.0838,
"accuracy": 1000
"accuracy": 1000,
"net": [{"description": "Google Inc.",
"address": "1600 Amphitheatre Parkway",
"city": "Mountain View",
"state": "CA",
"postal_code": "94043",
"country": "United States",
...
},
{...}
]
}
json:
{"error": "The address 127.0.0.1 is not in the database."