maxminddb 0.1.21 → 0.1.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/maxminddb.rb +13 -1
- data/lib/maxminddb/result.rb +4 -0
- data/lib/maxminddb/version.rb +1 -1
- data/maxminddb.gemspec +0 -2
- data/spec/maxminddb_spec.rb +8 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad81ea42768258609cdb8ed8212a4da3efd4bd4d
|
4
|
+
data.tar.gz: d7534f7038833a068b1ecf491a0792a382151824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99b03d59e8e3d46ef07652fcf6e07d2dd492492a7ee96f7e3feb5ded31b71055932b8112550dd3e3079dccda4f561c015edd9158886318e36331180aa5b19e0f
|
7
|
+
data.tar.gz: 718b0f9e14b4c38da3c43c0db7ebed587f8e6f83ac8b1c8c57c3c5175d6ba5591782ad0b47579fe7d5845f21f39ffd21a8a17116fc7861ce8a2a4a51da186764
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -101,3 +101,7 @@ The `LowMemoryReader` will not load the entire database into memory. It's import
|
|
101
101
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
102
102
|
4. Push to the branch (`git push origin my-new-feature`)
|
103
103
|
5. Create new Pull Request
|
104
|
+
|
105
|
+
## Also see
|
106
|
+
|
107
|
+
* [GeoLite2City](https://github.com/barsoom/geolite2_city), a Gem bundling the GeoLite2 City database.
|
data/lib/maxminddb.rb
CHANGED
@@ -63,7 +63,9 @@ module MaxMindDB
|
|
63
63
|
elsif next_node_no >= @node_count
|
64
64
|
data_section_start = @search_tree_size + DATA_SECTION_SEPARATOR_SIZE
|
65
65
|
pos = (next_node_no - @node_count) - DATA_SECTION_SEPARATOR_SIZE
|
66
|
-
|
66
|
+
result = decode(pos, data_section_start)[1]
|
67
|
+
result['network'] = network_from_addr(addr, i) unless result.empty?
|
68
|
+
return MaxMindDB::Result.new(result)
|
67
69
|
else
|
68
70
|
node_no = next_node_no
|
69
71
|
end
|
@@ -185,6 +187,16 @@ module MaxMindDB
|
|
185
187
|
addr = addr.ipv4_compat if addr.ipv4?
|
186
188
|
addr.to_i
|
187
189
|
end
|
190
|
+
|
191
|
+
def network_from_addr(addr, i)
|
192
|
+
fam = addr > 4294967295 ? Socket::AF_INET6 : Socket::AF_INET
|
193
|
+
ip = IPAddr.new(addr, family = fam)
|
194
|
+
|
195
|
+
subnet_size = ip.ipv4? ? i - 96 + 1 : i + 1
|
196
|
+
subnet = IPAddr.new("#{ip}/#{subnet_size}")
|
197
|
+
|
198
|
+
"#{subnet}/#{subnet_size}"
|
199
|
+
end
|
188
200
|
|
189
201
|
def is_local?(ip_or_hostname)
|
190
202
|
["127.0.0.1", "localhost", "::1", "0000::1", "0:0:0:0:0:0:0:1"].include? ip_or_hostname
|
data/lib/maxminddb/result.rb
CHANGED
data/lib/maxminddb/version.rb
CHANGED
data/maxminddb.gemspec
CHANGED
@@ -13,8 +13,6 @@ Gem::Specification.new do |spec|
|
|
13
13
|
spec.homepage = "https://github.com/yhirose/maxminddb"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
|
-
spec.post_install_message = "MIT"
|
17
|
-
|
18
16
|
spec.files = `git ls-files -z`.split("\x0")
|
19
17
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
20
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
data/spec/maxminddb_spec.rb
CHANGED
@@ -46,6 +46,10 @@ describe MaxMindDB do
|
|
46
46
|
it 'returns US as the country iso code' do
|
47
47
|
expect(country_db.lookup(ip).country.iso_code).to eq('US')
|
48
48
|
end
|
49
|
+
|
50
|
+
it 'returns 74.125.192.0/18 as network' do
|
51
|
+
expect(country_db.lookup(ip).network).to eq('74.125.192.0/18')
|
52
|
+
end
|
49
53
|
|
50
54
|
context 'as a Integer' do
|
51
55
|
let(:integer_ip) { IPAddr.new(ip).to_i }
|
@@ -78,6 +82,10 @@ describe MaxMindDB do
|
|
78
82
|
it 'returns FI as the country iso code' do
|
79
83
|
expect(country_db.lookup(ip).country.iso_code).to eq('FI')
|
80
84
|
end
|
85
|
+
|
86
|
+
it 'returns 2001:708::/32 as network' do
|
87
|
+
expect(country_db.lookup(ip).network).to eq('2001:708::/32')
|
88
|
+
end
|
81
89
|
|
82
90
|
context 'as an integer' do
|
83
91
|
let(:integer_ip) { IPAddr.new(ip).to_i }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maxminddb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- yhirose
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -104,7 +104,7 @@ homepage: https://github.com/yhirose/maxminddb
|
|
104
104
|
licenses:
|
105
105
|
- MIT
|
106
106
|
metadata: {}
|
107
|
-
post_install_message:
|
107
|
+
post_install_message:
|
108
108
|
rdoc_options: []
|
109
109
|
require_paths:
|
110
110
|
- lib
|