mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-11 15:56:07 -07:00
Lookup IP address ISP info
This commit is contained in:
parent
469d22a833
commit
aba39d06bf
4 changed files with 68 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue