aboutsummaryrefslogtreecommitdiff
path: root/license_protected_downloads
diff options
context:
space:
mode:
authorAndy Doan <andy.doan@linaro.org>2016-01-04 16:21:59 -0600
committerAndy Doan <andy.doan@linaro.org>2016-01-04 16:21:59 -0600
commit27ac3448cd511e02f608a9ddb3411c4c6a5ef853 (patch)
treea1b6ab0d06223e8d7ba4a5ff194407c80d859d67 /license_protected_downloads
parentda9238ebc3143964954fa100125e98a520b06570 (diff)
reports: handle IPv6 addresses
We occasionally see an IPv6 address come in via an IPv4 tunnel. ie: HTTP_X_FORWARDED_FOR = ipv6 REMOTE_ADDR = the ipv4 proxy We don't have an IPV6 capability lookup database and they don't seem that accurate. Furthermore, these don't currently happen often enough to be statistically relevant. So we'll just fill in ipv6-unknown for now and can come back at a later date if we want to try and fix. Change-Id: Ib18430638dd6484680ac2f95e57f6cb5859163a6
Diffstat (limited to 'license_protected_downloads')
-rw-r--r--license_protected_downloads/management/commands/downloads_report.py12
-rw-r--r--license_protected_downloads/models.py3
2 files changed, 9 insertions, 6 deletions
diff --git a/license_protected_downloads/management/commands/downloads_report.py b/license_protected_downloads/management/commands/downloads_report.py
index 190dd47..5b1de84 100644
--- a/license_protected_downloads/management/commands/downloads_report.py
+++ b/license_protected_downloads/management/commands/downloads_report.py
@@ -18,11 +18,15 @@ class Command(BaseCommand):
for download in Download.objects.filter(country=None):
try:
loc = ipl.get_all(download.ip)
+ download.country = loc.country_short
+ download.region_isp = '%s / %s' % (loc.region, loc.isp)
except:
- print "Unable to get IP location data for:", download.id
- raise
- download.country = loc.country_short
- download.region_isp = '%s / %s' % (loc.region, loc.isp)
+ if ':' in download.ip:
+ print 'Inserting ipv6-unknown for', download.id
+ download.country = download.region_isp = 'ipv6-unknown'
+ else:
+ print "Unable to get IP location data for:", download.id
+ raise
download.save()
def _find_dups(self):
diff --git a/license_protected_downloads/models.py b/license_protected_downloads/models.py
index 3e98175..b29efba 100644
--- a/license_protected_downloads/models.py
+++ b/license_protected_downloads/models.py
@@ -26,13 +26,12 @@ def get_ip(request):
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
- 'HTTP_VIA',
'X_FORWARDED_FOR',
'REMOTE_ADDR',
)
for field in ip_meta_vals:
ip = request.META.get(field)
- if ip:
+ if ip and ip != 'unknown':
return ip.split(',')[0]
return 'unkwnown'