mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -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
13
API.md
13
API.md
|
@ -342,7 +342,18 @@ Returns:
|
|||
"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."
|
||||
|
|
|
@ -34,6 +34,15 @@
|
|||
<li>Accuracy Radius: <strong><span id="accuracy"></span></strong></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="col-sm-12">
|
||||
<h4><strong>Connection Details</strong></h4>
|
||||
</div>
|
||||
<div class="col-sm-6" id="isp_instance">
|
||||
<ul class="list-unstyled">
|
||||
<li>ISP: <strong><span id="isp"></span></strong></li>
|
||||
<li>Address: <strong><span id="isp_address"></span></strong></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<% from plexpy.helpers import anon_url %>
|
||||
|
@ -67,6 +76,26 @@
|
|||
$('#latitude').html(data.latitude);
|
||||
$('#longitude').html(data.longitude);
|
||||
$('#accuracy').html(data.accuracy + ' km');
|
||||
|
||||
var nets = data.nets;
|
||||
if (!(nets.length)) {
|
||||
$('#isp').html('Not Found')
|
||||
$('#isp_address').html('Not Found')
|
||||
} else {
|
||||
$('#isp_instance').remove();
|
||||
$.each(nets, function (index, net) {
|
||||
$('#modal-text').append('<div class="col-sm-6"> \
|
||||
<ul class="list-unstyled"> \
|
||||
<li>ISP: <strong>' + net.description + '</strong></li> \
|
||||
<li><span style="float: left;">Address: </span> \
|
||||
<span style="float: left;"><strong>' + net.address + '</strong><br /> \
|
||||
<strong>' + net.city + ", " + net.state + " " + net.postal_code + '</strong><br /> \
|
||||
<strong>' + net.country + '</strong></span> \
|
||||
</li> \
|
||||
</ul> \
|
||||
</div>')
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -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