add reverse dns lookup results for viewer's current IPs to session, show on hosts overview view (see panel at lower right)
not showing it in home view's jumbotron due to potential cosmetic issues
This commit is contained in:
parent
71509fe935
commit
6b9c7e9511
@ -79,7 +79,9 @@ class AjaxGetIps(View):
|
|||||||
"""
|
"""
|
||||||
response = dict(
|
response = dict(
|
||||||
ipv4=request.session.get('ipv4', ''),
|
ipv4=request.session.get('ipv4', ''),
|
||||||
|
ipv4_rdns=request.session.get('ipv4_rdns', ''),
|
||||||
ipv6=request.session.get('ipv6', ''),
|
ipv6=request.session.get('ipv6', ''),
|
||||||
|
ipv6_rdns=request.session.get('ipv6_rdns', ''),
|
||||||
)
|
)
|
||||||
logger.debug("ajax_get_ips response: %r" % (response, ))
|
logger.debug("ajax_get_ips response: %r" % (response, ))
|
||||||
return HttpResponse(json.dumps(response), content_type='application/json')
|
return HttpResponse(json.dumps(response), content_type='application/json')
|
||||||
|
@ -187,10 +187,18 @@ def rev_lookup(ipaddr):
|
|||||||
"""
|
"""
|
||||||
do a normal reverse DNS lookup, IP to name
|
do a normal reverse DNS lookup, IP to name
|
||||||
|
|
||||||
|
note: this call may be slow, especially if there is no reverse dns entry
|
||||||
|
|
||||||
:param ipaddr: ip address (str)
|
:param ipaddr: ip address (str)
|
||||||
:return: hostname
|
:return: hostname (or empty string if lookup failed)
|
||||||
"""
|
"""
|
||||||
return socket.gethostbyaddr(ipaddr)[0]
|
name = ''
|
||||||
|
if ipaddr:
|
||||||
|
try:
|
||||||
|
name = socket.gethostbyaddr(ipaddr)[0]
|
||||||
|
except socket.error:
|
||||||
|
pass
|
||||||
|
return name
|
||||||
|
|
||||||
|
|
||||||
def parse_name(fqdn, origin=None):
|
def parse_name(fqdn, origin=None):
|
||||||
@ -337,8 +345,9 @@ def put_ip_into_session(session, ipaddr, kind=None, max_age=0,
|
|||||||
# we try to avoid modifying the session if not necessary...
|
# we try to avoid modifying the session if not necessary...
|
||||||
if session.get(kind) != ipaddr:
|
if session.get(kind) != ipaddr:
|
||||||
# we have a new ip, remember it, with timestamp
|
# we have a new ip, remember it, with timestamp
|
||||||
session[kind] = ipaddr
|
|
||||||
session[kind + '_timestamp'] = int(time.time())
|
session[kind + '_timestamp'] = int(time.time())
|
||||||
|
session[kind] = ipaddr
|
||||||
|
session[kind + '_rdns'] = rev_lookup(ipaddr) # may be slow
|
||||||
else:
|
else:
|
||||||
old_timestamp = session.get(kind + '_timestamp')
|
old_timestamp = session.get(kind + '_timestamp')
|
||||||
if not max_age or old_timestamp is None or old_timestamp + max_age < int(time.time()):
|
if not max_age or old_timestamp is None or old_timestamp + max_age < int(time.time()):
|
||||||
|
@ -61,8 +61,12 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="well well-sm">
|
<div class="well well-sm">
|
||||||
<h3>Your current IP(s):</h3>
|
<h3>Your current IP(s):</h3>
|
||||||
<p><b>IPv4:</b> <span id="ipv4" class="ipv4addr">{{ request.session.ipv4 }}</span></p>
|
<p><b>IPv4:</b> <span id="ipv4" class="ipv4addr">{{ request.session.ipv4 }}</span>
|
||||||
<p><b>IPv6:</b> <span id="ipv6" class="ipv6addr">{{ request.session.ipv6 }}</span></p>
|
<span id="ipv4_rdns" class="ipv4addr">{{ request.session.ipv4_rdns }}</span>
|
||||||
|
</p>
|
||||||
|
<p><b>IPv6:</b> <span id="ipv6" class="ipv6addr">{{ request.session.ipv6 }}</span>
|
||||||
|
<span id="ipv6_rdns" class="ipv6addr">{{ request.session.ipv6_rdns }}</span>
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -155,7 +155,9 @@
|
|||||||
$.getJSON("{% url 'ajax_get_ips' %}")
|
$.getJSON("{% url 'ajax_get_ips' %}")
|
||||||
.done(function(data) {
|
.done(function(data) {
|
||||||
$('#ipv4').text(data['ipv4']);
|
$('#ipv4').text(data['ipv4']);
|
||||||
|
$('#ipv4_rdns').text(data['ipv4_rdns']);
|
||||||
$('#ipv6').text(data['ipv6']);
|
$('#ipv6').text(data['ipv6']);
|
||||||
|
$('#ipv6_rdns').text(data['ipv6_rdns']);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setTimeout(insert_ips, 1500);
|
setTimeout(insert_ips, 1500);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user