maxminddb 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ab8d608c0e8a6e577bdf66c0d2523c33f8d61154
4
- data.tar.gz: 7e2ab98277eef7c50c62e8878082ac404aade464
3
+ metadata.gz: ad81ea42768258609cdb8ed8212a4da3efd4bd4d
4
+ data.tar.gz: d7534f7038833a068b1ecf491a0792a382151824
5
5
  SHA512:
6
- metadata.gz: 3c002cc49899ffa54ee320eb2c867e7b88d50e343da99a88217b5a7f0251863c1be4c8fc98c70c2038efd6362df78db1b8c2ff7ce77782d3d14fee561d2bdd75
7
- data.tar.gz: a4888c65e1bf9bc8381f16c837f3b86cbd12f9dbf62eb840767ece6e8c18b2180cddff71c14b0630a49357635404176bf5dd9417a960c1bb6b01212c48db781d
6
+ metadata.gz: 99b03d59e8e3d46ef07652fcf6e07d2dd492492a7ee96f7e3feb5ded31b71055932b8112550dd3e3079dccda4f561c015edd9158886318e36331180aa5b19e0f
7
+ data.tar.gz: 718b0f9e14b4c38da3c43c0db7ebed587f8e6f83ac8b1c8c57c3c5175d6ba5591782ad0b47579fe7d5845f21f39ffd21a8a17116fc7861ce8a2a4a51da186764
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ### 0.1.22 (September 15, 2018)
4
+
5
+ - Result includes 'network'
6
+
3
7
  ### 0.1.21 (July 20, 2018)
4
8
 
5
9
  - Make the low-memory file reader opt-in
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.
@@ -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
- return MaxMindDB::Result.new(decode(pos, data_section_start)[1])
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
@@ -57,6 +57,10 @@ module MaxMindDB
57
57
  def connection_type
58
58
  @_connection_type ||= raw['connection_type']
59
59
  end
60
+
61
+ def network
62
+ @_network ||= raw['network']
63
+ end
60
64
 
61
65
  def to_hash
62
66
  @_to_hash ||= raw.clone
@@ -1,3 +1,3 @@
1
1
  module MaxMindDB
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
@@ -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)/})
@@ -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.21
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-07-21 00:00:00.000000000 Z
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: MIT
107
+ post_install_message:
108
108
  rdoc_options: []
109
109
  require_paths:
110
110
  - lib