Skip to content

Commit 0505584

Browse files
authored
Merge pull request #46 from maxmind/greg/anonymizer
Add new anonymizer outputs for Insights
2 parents 2c6d622 + 262f5b5 commit 0505584

File tree

3 files changed

+71
-7
lines changed

3 files changed

+71
-7
lines changed

HISTORY.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
History
44
-------
55

6+
2.6.0 (2017-XX-XX)
7+
++++++++++++++++++
8+
9+
* The following new anonymizer outputs were added to ``geoip2.record.Traits``
10+
for use with GeoIP2 Precision Insights: ``is_anonymous``,
11+
``is_anonymous_vpn``, ``is_hosting_provider``, ``is_public_proxy``, and
12+
``is_tor_exit_node``.
13+
614
2.5.0 (2017-05-08)
715
++++++++++++++++++
816

geoip2/records.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,13 @@ class Traits(Record):
517517
518518
:type: unicode
519519
520+
.. attribute:: is_anonymous
521+
522+
This is true if the IP address belongs to any sort of anonymous network.
523+
This attribute is only available from GeoIP2 Precision Insights.
524+
525+
:type: bool
526+
520527
.. attribute:: is_anonymous_proxy
521528
522529
This is true if the IP is an anonymous
@@ -530,6 +537,20 @@ class Traits(Record):
530537
<https://www.maxmind.com/en/geoip2-anonymous-ip-database GeoIP2>`_
531538
instead.
532539
540+
.. attribute:: is_anonymous_vpn
541+
542+
This is true if the IP address belongs to an anonymous VPN system.
543+
This attribute is only available from GeoIP2 Precision Insights.
544+
545+
:type: bool
546+
547+
.. attribute:: is_hosting_provider
548+
549+
This is true if the IP address belongs to a hosting provider.
550+
This attribute is only available from GeoIP2 Precision Insights.
551+
552+
:type: bool
553+
533554
.. attribute:: is_legitimate_proxy
534555
535556
This attribute is true if MaxMind believes this IP address to be a
@@ -538,6 +559,13 @@ class Traits(Record):
538559
539560
:type: bool
540561
562+
.. attribute:: is_public_proxy
563+
564+
This is true if the IP address belongs to a public proxy. This attribute
565+
is only available from GeoIP2 Precision Insights.
566+
567+
:type: bool
568+
541569
.. attribute:: is_satellite_provider
542570
543571
This is true if the IP address is from a satellite provider that
@@ -551,6 +579,13 @@ class Traits(Record):
551579
output does not provide sufficiently relevant data for us to maintain
552580
it.
553581
582+
.. attribute:: is_tor_exit_node
583+
584+
This is true if the IP address is a Tor exit node. This attribute is
585+
only available from GeoIP2 Precision Insights.
586+
587+
:type: bool
588+
554589
.. attribute:: isp
555590
556591
The name of the ISP associated with the IP address. This attribute is
@@ -597,15 +632,23 @@ class Traits(Record):
597632

598633
_valid_attributes = set([
599634
'autonomous_system_number', 'autonomous_system_organization',
600-
'connection_type', 'domain', 'is_anonymous_proxy',
601-
'is_legitimate_proxy', 'is_satellite_provider', 'isp', 'ip_address',
602-
'organization', 'user_type'
635+
'connection_type', 'domain', 'is_anonymous', 'is_anonymous_proxy',
636+
'is_anonymous_vpn', 'is_hosting_provider', 'is_legitimate_proxy',
637+
'is_public_proxy', 'is_satellite_provider', 'is_tor_exit_node',
638+
'is_satellite_provider', 'isp', 'ip_address', 'organization',
639+
'user_type'
603640
])
604641

605642
def __init__(self, **kwargs):
606643
for k in [
607-
'is_anonymous_proxy', 'is_legitimate_proxy',
608-
'is_satellite_provider'
644+
'is_anonymous',
645+
'is_anonymous_proxy',
646+
'is_anonymous_vpn',
647+
'is_hosting_provider',
648+
'is_legitimate_proxy',
649+
'is_public_proxy',
650+
'is_satellite_provider',
651+
'is_tor_exit_node',
609652
]:
610653
kwargs[k] = bool(kwargs.get(k, False))
611654
super(Traits, self).__init__(**kwargs)

tests/models_test.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,13 @@ def test_insights_full(self):
9090
'autonomous_system_organization': 'AS Organization',
9191
'domain': 'example.com',
9292
'ip_address': '1.2.3.4',
93-
'is_anonymous_proxy': 0,
94-
'is_us_military': 1,
93+
'is_anonymous': True,
94+
'is_anonymous_proxy': True,
95+
'is_anonymous_vpn': True,
96+
'is_hosting_provider': True,
97+
'is_public_proxy': True,
98+
'is_satellite_provider': True,
99+
'is_tor_exit_node': True,
95100
'isp': 'Comcast',
96101
'network_speed': 'cable/DSL',
97102
'organization': 'Blorg',
@@ -169,6 +174,14 @@ def test_insights_full(self):
169174
eval(repr(model.location)),
170175
"Location repr can be eval'd")
171176

177+
self.assertTrue(model.traits.is_anonymous)
178+
self.assertTrue(model.traits.is_anonymous_proxy)
179+
self.assertTrue(model.traits.is_anonymous_vpn)
180+
self.assertTrue(model.traits.is_hosting_provider)
181+
self.assertTrue(model.traits.is_public_proxy)
182+
self.assertTrue(model.traits.is_satellite_provider)
183+
self.assertTrue(model.traits.is_tor_exit_node)
184+
172185
def test_insights_min(self):
173186
model = geoip2.models.Insights({'traits': {'ip_address': '5.6.7.8'}})
174187
self.assertEqual(

0 commit comments

Comments
 (0)