Skip to content

Commit ab71702

Browse files
committed
Add Anonymous Plus support
1 parent 5b021ce commit ab71702

File tree

6 files changed

+113
-1
lines changed

6 files changed

+113
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
## 1.3.0
44

5+
* Support for the GeoIP Anonymous Plus database has been added. To do a
6+
lookup in this database, use the `anonymous_plus` method on
7+
`MaxMind::GeoIP2::Reader`.
58
* Ruby 3.0+ is now required. If you're using Ruby 2.5, 2.6, or 2.7, please
69
use version 1.2.0 of this gem.
710
* Deprecated `metro_code` on `MaxMind::GeoIP2::Record::Location`. The code

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,21 @@ record = reader.anonymous_ip('128.101.101.101')
133133
puts "Anonymous" if record.is_anonymous
134134
```
135135

136+
### Anonymous Plus Example
137+
138+
```ruby
139+
require 'maxmind/geoip2'
140+
141+
# This creates the Reader object which should be reused across lookups.
142+
reader = MaxMind::GeoIP2::Reader.new(
143+
database: '/usr/share/GeoIP/GeoIP-Anonymous-Plus.mmdb',
144+
)
145+
146+
record = reader.anonymous_ip('128.101.101.101')
147+
148+
puts record.anonymizer_confidence # 30
149+
```
150+
136151
### ASN Example
137152

138153
```ruby
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'date'
4+
require 'maxmind/geoip2/model/anonymous_ip'
5+
6+
module MaxMind
7+
module GeoIP2
8+
module Model
9+
# Model class for the Anonymous Plus database.
10+
class AnonymousPlus < AnonymousIP
11+
# A score ranging from 1 to 99 that is our percent confidence that the
12+
# network is currently part of an actively used VPN service.
13+
#
14+
# @return [Integer, nil]
15+
def anonymizer_confidence
16+
get('anonymizer_confidence')
17+
end
18+
19+
# The last day that the network was sighted in our analysis of
20+
# anonymized networks. This value is parsed lazily.
21+
#
22+
# @return [Date, nil] A Date object representing the last seen date,
23+
# or nil if the date is not available.
24+
def network_last_seen
25+
return @_parsed_network_last_seen if defined?(@_parsed_network_last_seen)
26+
27+
date_string = get('network_last_seen')
28+
29+
if !date_string
30+
return nil
31+
end
32+
33+
@_parsed_network_last_seen = Date.parse(date_string)
34+
end
35+
36+
# The name of the VPN provider (e.g., NordVPN, SurfShark, etc.)
37+
# associated with the network.
38+
#
39+
# @return [String, nil]
40+
def provider_name
41+
get('provider_name')
42+
end
43+
end
44+
end
45+
end
46+
end

lib/maxmind/geoip2/reader.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'maxmind/db'
44
require 'maxmind/geoip2/errors'
55
require 'maxmind/geoip2/model/anonymous_ip'
6+
require 'maxmind/geoip2/model/anonymous_plus'
67
require 'maxmind/geoip2/model/asn'
78
require 'maxmind/geoip2/model/city'
89
require 'maxmind/geoip2/model/connection_type'
@@ -110,6 +111,30 @@ def anonymous_ip(ip_address)
110111
)
111112
end
112113

114+
# Look up the IP address in the Anonymous Plus database.
115+
#
116+
# @param ip_address [String] a string in the standard notation. It may be
117+
# IPv4 or IPv6.
118+
#
119+
# @return [MaxMind::GeoIP2::Model::AnonymousPlus]
120+
#
121+
# @raise [ArgumentError] if used against a non-Anonymous Plus database
122+
# or if you attempt to look up an IPv6 address in an IPv4 only database.
123+
#
124+
# @raise [AddressNotFoundError] if the IP address is not found in the
125+
# database.
126+
#
127+
# @raise [MaxMind::DB::InvalidDatabaseError] if the database appears
128+
# corrupt.
129+
def anonymous_plus(ip_address)
130+
flat_model_for(
131+
Model::AnonymousPlus,
132+
'anonymous_plus',
133+
'GeoIP-Anonymous-Plus',
134+
ip_address,
135+
)
136+
end
137+
113138
# Look up the IP address in an ASN database.
114139
#
115140
# @param ip_address [String] a string in the standard notation. It may be

test/data

Submodule data updated 57 files

test/test_reader.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,29 @@ def test_anonymous_ip_residential_proxy
3737
reader.close
3838
end
3939

40+
def test_anonymous_plus
41+
reader = MaxMind::GeoIP2::Reader.new(
42+
'test/data/test-data/GeoIP-Anonymous-Plus-Test.mmdb',
43+
)
44+
ip = '1.2.0.1'
45+
record = reader.anonymous_plus(ip)
46+
47+
assert_equal(30, record.anonymizer_confidence)
48+
assert_equal(true, record.anonymous?)
49+
assert_equal(true, record.anonymous_vpn?)
50+
assert_equal(false, record.hosting_provider?)
51+
assert_equal(Date.new(2025, 4, 14), record.network_last_seen)
52+
assert_equal('foo', record.provider_name)
53+
assert_equal(false, record.public_proxy?)
54+
assert_equal(false, record.residential_proxy?)
55+
assert_equal(false, record.tor_exit_node?)
56+
57+
assert_equal(ip, record.ip_address)
58+
assert_equal('1.2.0.1/32', record.network)
59+
60+
reader.close
61+
end
62+
4063
def test_asn
4164
reader = MaxMind::GeoIP2::Reader.new(
4265
'test/data/test-data/GeoLite2-ASN-Test.mmdb',

0 commit comments

Comments
 (0)