mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-07-10 07:22:37 -07:00
Add Host to IP lookup
This commit is contained in:
parent
ba8e4ff33c
commit
7c159e97de
4 changed files with 68 additions and 44 deletions
27
API.md
27
API.md
|
@ -1706,7 +1706,7 @@ Returns:
|
||||||
|
|
||||||
|
|
||||||
### get_whois_lookup
|
### get_whois_lookup
|
||||||
Get the ISP info for an IP address.
|
Get the connection info for an IP address.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
|
@ -1717,18 +1717,21 @@ Optional parameters:
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
json:
|
json:
|
||||||
[{"description": "Google Inc.",
|
{"host": "google-public-dns-a.google.com",
|
||||||
"address": "1600 Amphitheatre Parkway",
|
"nets": [{"description": "Google Inc.",
|
||||||
"city": "Mountain View",
|
"address": "1600 Amphitheatre Parkway",
|
||||||
"state": "CA",
|
"city": "Mountain View",
|
||||||
"postal_code": "94043",
|
"state": "CA",
|
||||||
"country": "United States",
|
"postal_code": "94043",
|
||||||
...
|
"country": "United States",
|
||||||
},
|
...
|
||||||
{...}
|
},
|
||||||
]
|
{...}
|
||||||
|
]
|
||||||
json:
|
json:
|
||||||
{"error": "The address 127.0.0.1 is not in the database."
|
{"host": "Not available",
|
||||||
|
"nets": [],
|
||||||
|
"error": "IPv4 address 127.0.0.1 is already defined as Loopback via RFC 1122, Section 3.2.1.3."
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,14 @@
|
||||||
<h4><strong>Connection Details</strong><span id="isp_loading" style="padding-left: 5px;"><i class="fa fa-refresh fa-spin"></i></span></h4>
|
<h4><strong>Connection Details</strong><span id="isp_loading" style="padding-left: 5px;"><i class="fa fa-refresh fa-spin"></i></span></h4>
|
||||||
</div>
|
</div>
|
||||||
<div id="isp_error" class="col-sm-12 text-muted"></div>
|
<div id="isp_error" class="col-sm-12 text-muted"></div>
|
||||||
|
<div class="col-sm-12">
|
||||||
|
<ul class="list-unstyled">
|
||||||
|
<li>Host: <strong><span id="isp_host"></span></strong></li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
<div class="col-sm-6" id="isp_instance">
|
<div class="col-sm-6" id="isp_instance">
|
||||||
<ul class="list-unstyled">
|
<ul class="list-unstyled">
|
||||||
<li>ISP: <strong><span id="isp"></span></strong></li>
|
<li>ISP: <strong><span id="isp_name"></span></strong></li>
|
||||||
<li>Address: <strong><span id="isp_address"></span></strong></li>
|
<li>Address: <strong><span id="isp_address"></span></strong></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -99,13 +104,12 @@
|
||||||
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> Internal request failed.').show();
|
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> Internal request failed.').show();
|
||||||
},
|
},
|
||||||
success: function (data) {
|
success: function (data) {
|
||||||
|
$('#isp_host').html(data.host);
|
||||||
if ('error' in data) {
|
if ('error' in data) {
|
||||||
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> ' + data.error).show();
|
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> ' + data.error).show();
|
||||||
} else if (!(data.length)) {
|
} else if (data.nets.length) {
|
||||||
$('#isp_error').html('<i class="fa fa-exclamation-circle"></i> Connection details not found.').show();
|
|
||||||
} else {
|
|
||||||
$('#isp_instance').remove();
|
$('#isp_instance').remove();
|
||||||
$.each(data, function (index, net) {
|
$.each(data.nets, function (index, net) {
|
||||||
var s = '';
|
var s = '';
|
||||||
if (net.city || net.state || net.postal_code) {
|
if (net.city || net.state || net.postal_code) {
|
||||||
s = (net.city && net.state) ? net.city + ', ' + net.state : net.city || net.state || '';
|
s = (net.city && net.state) ? net.city + ', ' + net.state : net.city || net.state || '';
|
||||||
|
@ -113,15 +117,17 @@
|
||||||
}
|
}
|
||||||
s = (s) ? '<strong>' + s + '</strong><br />' : s;
|
s = (s) ? '<strong>' + s + '</strong><br />' : s;
|
||||||
$('#modal-text').append('<div class="col-sm-6"> \
|
$('#modal-text').append('<div class="col-sm-6"> \
|
||||||
<ul class="list-unstyled"> \
|
<ul class="list-unstyled"> \
|
||||||
<li>ISP: <strong>' + net.description + '</strong></li> \
|
<li>ISP: <strong>' + net.description + '</strong></li> \
|
||||||
<li><span style="float: left;">Address: </span> \
|
<li><span style="float: left;">Address: </span> \
|
||||||
<span style="float: left;"><strong>' + net.address + '</strong><br />' + s +
|
<span style="float: left;"><strong>' + net.address + '</strong><br />' + s +
|
||||||
'<strong>' + net.country + '</strong></span> \
|
'<strong>' + net.country + '</strong></span> \
|
||||||
</li> \
|
</li> \
|
||||||
</ul> \
|
</ul> \
|
||||||
</div>')
|
</div>')
|
||||||
});
|
});
|
||||||
|
} else {
|
||||||
|
$('#isp_name, #isp_address').html("Not available");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -632,6 +632,7 @@ def geoip_lookup(ip_address):
|
||||||
def whois_lookup(ip_address):
|
def whois_lookup(ip_address):
|
||||||
|
|
||||||
nets = []
|
nets = []
|
||||||
|
err = None
|
||||||
try:
|
try:
|
||||||
whois = ipwhois.IPWhois(ip_address).lookup_whois(retry_count=0)
|
whois = ipwhois.IPWhois(ip_address).lookup_whois(retry_count=0)
|
||||||
countries = ipwhois.utils.get_countries()
|
countries = ipwhois.utils.get_countries()
|
||||||
|
@ -641,15 +642,28 @@ def whois_lookup(ip_address):
|
||||||
if net['postal_code']:
|
if net['postal_code']:
|
||||||
net['postal_code'] = net['postal_code'].replace('-', ' ')
|
net['postal_code'] = net['postal_code'].replace('-', ' ')
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
return 'Invalid IP address provided: %s.' % ip_address
|
err = 'Invalid IP address provided: %s.' % ip_address
|
||||||
except ipwhois.exceptions.IPDefinedError as e:
|
except ipwhois.exceptions.IPDefinedError as e:
|
||||||
return '%s' % e
|
err = '%s' % e
|
||||||
except ipwhois.exceptions.ASNRegistryError as e:
|
except ipwhois.exceptions.ASNRegistryError as e:
|
||||||
return '%s' % e
|
err = '%s' % e
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return 'Error: %s' % e
|
err = 'Error: %s' % e
|
||||||
|
|
||||||
return nets
|
host = ''
|
||||||
|
try:
|
||||||
|
host = ipwhois.Net(ip_address).get_host(retry_count=0)[0]
|
||||||
|
except Exception as e:
|
||||||
|
host = 'Not available'
|
||||||
|
|
||||||
|
whois_info = {"host": host,
|
||||||
|
"nets": nets
|
||||||
|
}
|
||||||
|
|
||||||
|
if err:
|
||||||
|
whois_info['error'] = err
|
||||||
|
|
||||||
|
return whois_info
|
||||||
|
|
||||||
# Taken from SickRage
|
# Taken from SickRage
|
||||||
def anon_url(*url):
|
def anon_url(*url):
|
||||||
|
|
|
@ -4327,7 +4327,7 @@ class WebInterface(object):
|
||||||
@requireAuth()
|
@requireAuth()
|
||||||
@addtoapi()
|
@addtoapi()
|
||||||
def get_whois_lookup(self, ip_address='', **kwargs):
|
def get_whois_lookup(self, ip_address='', **kwargs):
|
||||||
""" Get the ISP info for an IP address.
|
""" Get the connection info for an IP address.
|
||||||
|
|
||||||
```
|
```
|
||||||
Required parameters:
|
Required parameters:
|
||||||
|
@ -4338,22 +4338,23 @@ class WebInterface(object):
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
json:
|
json:
|
||||||
[{"description": "Google Inc.",
|
{"host": "google-public-dns-a.google.com",
|
||||||
"address": "1600 Amphitheatre Parkway",
|
"nets": [{"description": "Google Inc.",
|
||||||
"city": "Mountain View",
|
"address": "1600 Amphitheatre Parkway",
|
||||||
"state": "CA",
|
"city": "Mountain View",
|
||||||
"postal_code": "94043",
|
"state": "CA",
|
||||||
"country": "United States",
|
"postal_code": "94043",
|
||||||
...
|
"country": "United States",
|
||||||
},
|
...
|
||||||
{...}
|
},
|
||||||
]
|
{...}
|
||||||
|
]
|
||||||
json:
|
json:
|
||||||
{"error": "The address 127.0.0.1 is not in the database."
|
{"host": "Not available",
|
||||||
|
"nets": [],
|
||||||
|
"error": "IPv4 address 127.0.0.1 is already defined as Loopback via RFC 1122, Section 3.2.1.3."
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
"""
|
"""
|
||||||
whois_info = helpers.whois_lookup(ip_address)
|
whois_info = helpers.whois_lookup(ip_address)
|
||||||
if isinstance(whois_info, basestring):
|
|
||||||
return {'error': whois_info}
|
|
||||||
return whois_info
|
return whois_info
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue