From 8a1a2071aa9e055568ec43d0c1486ab3f655d49d Mon Sep 17 00:00:00 2001 From: Andrew Williams Date: Wed, 4 Apr 2012 20:17:18 +0100 Subject: [PATCH] Added some DNS lookup for the IP viewer --- app/sso/models.py | 16 ++++++++++++++++ app/sso/templates/sso/ssouseripaddress_list.html | 5 +++-- requirements.txt | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/app/sso/models.py b/app/sso/models.py index d8d9abc..27da92f 100644 --- a/app/sso/models.py +++ b/app/sso/models.py @@ -11,6 +11,9 @@ from django.contrib.contenttypes import generic from django.utils import simplejson as json from jsonfield.fields import JSONField +from IPy import IP +import dns.resolver + from eve_api.models import EVEAccount, EVEPlayerCorporation, EVEPlayerAlliance, EVEPlayerCharacter from sso.app_defines import * @@ -89,6 +92,19 @@ class SSOUserIPAddress(models.Model): ip_address = models.CharField("IP Address", max_length=200, blank=False) user = models.ForeignKey(User, blank=False, null=False, related_name='ip_addresses') + @property + def hostname(self): + arpa = IP(self.ip_address).reverseName() + try: + res = dns.resolver.query(arpa, 'PTR').response + return res.answer[0][0].to_text() + except: + return arpa + + @property + def related_users(self): + return SSOUserIPAddress.objects.filter(ip_address=self.ip_address).count() + def __unicode__(self): return self.ip_address diff --git a/app/sso/templates/sso/ssouseripaddress_list.html b/app/sso/templates/sso/ssouseripaddress_list.html index 9b825a4..171392f 100644 --- a/app/sso/templates/sso/ssouseripaddress_list.html +++ b/app/sso/templates/sso/ssouseripaddress_list.html @@ -8,11 +8,12 @@ {% if object_list %} - + {% for object in object_list %} - + + diff --git a/requirements.txt b/requirements.txt index dca717d..acea387 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,5 @@ nexus -e git+https://github.com/nikdoof/gargoyle.git@dca57fc4b437b85f8cbc#egg=gargoyle beautifulsoup django-redis-cache +IPy==0.75 +dnspython
IP AddressUserFirst UseLast Use
IP AddressHostnameUserFirst UseLast Use
{{ object.ip_address }}
{{ object.ip_address }} {% if object.related_users > 1 %}({{ object.related_users }} users){% endif %}{{ object.hostname }} {{ object.user }} (Profile) {{ object.first_seen }} {{ object.last_seen }}