ip2location_ruby 8.7.3 → 8.8.1
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 +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +1 -1
- data/VERSION +1 -1
- data/example.rb +3 -0
- data/ip2location_ruby.gemspec +12 -29
- data/lib/ip2location_ruby/database_config.rb +4 -1
- data/lib/ip2location_ruby/i2l_string_data.rb +14 -11
- data/lib/ip2location_ruby.rb +67 -1
- data/rb/data/IP2LOCATION-COUNTRY-INFORMATION-BASIC.CSV +249 -249
- data/rb/data/IP2LOCATION-ISO3166-2.CSV +3625 -3625
- data/spec/ip2location_ruby_database_spec.rb +18 -0
- data/spec/ip2location_ruby_iptools_spec.rb +1 -1
- metadata +10 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 977ac426ebd7ff2a2d6f39ab1727a5afd10ba19af91e98b2109576740f2221c5
|
|
4
|
+
data.tar.gz: 964283f98279e11d60f24ebfc3c0da115b756b1ae23b8e33856195c72fc829e6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2b066e16d50591e514e623c7e3b54e26c05053cf04bbbe3f7682ab13f7dd12e3875a0dc19fe26f6e5ebc3ead5c6379b5f3b4dc21b88d509edf44f085cfd8793b
|
|
7
|
+
data.tar.gz: 7dde61e91effb12121643a44f48114d9dc0e8d3cf98175eb7fff8f8776e0f8be245ffa13969d6c7cbc80a198560d7a8f88924ba6fe14d50236c17d36777d3c21
|
data/Gemfile
CHANGED
|
@@ -2,12 +2,12 @@ source "http://rubygems.org"
|
|
|
2
2
|
# Add dependencies required to use your gem here.
|
|
3
3
|
# Example:
|
|
4
4
|
# gem "activesupport", ">= 2.3.5"
|
|
5
|
-
gem 'bindata', "~>
|
|
5
|
+
gem 'bindata', "~> 3.0"
|
|
6
6
|
# Add dependencies to develop your gem here.
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
|
8
8
|
|
|
9
9
|
group :development do
|
|
10
|
-
gem "rspec", "~>
|
|
11
|
-
gem "rdoc", "
|
|
12
|
-
gem "bundler", ">=
|
|
10
|
+
gem "rspec", "~> 3.13"
|
|
11
|
+
gem "rdoc", ">= 6.3.1"
|
|
12
|
+
gem "bundler", ">= 2.4"
|
|
13
13
|
end
|
data/LICENSE.txt
CHANGED
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
8.
|
|
1
|
+
8.8.1
|
data/example.rb
CHANGED
|
@@ -32,6 +32,9 @@ puts 'Category: ' + record['category']
|
|
|
32
32
|
puts 'District: ' + record['district']
|
|
33
33
|
puts 'ASN: ' + record['asn']
|
|
34
34
|
puts 'AS: ' + record['as']
|
|
35
|
+
puts 'AS Domain: ' + record['as_domain']
|
|
36
|
+
puts 'AS Usage Type: ' + record['as_usagetype']
|
|
37
|
+
puts 'AS CIDR: ' + record['as_cidr']
|
|
35
38
|
i2l.close()
|
|
36
39
|
|
|
37
40
|
# IP Tools
|
data/ip2location_ruby.gemspec
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Gem::Specification.new do |s|
|
|
2
2
|
s.name = "ip2location_ruby"
|
|
3
|
-
s.version = "8.
|
|
3
|
+
s.version = "8.8.1"
|
|
4
4
|
|
|
5
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
6
6
|
s.require_paths = ["lib"]
|
|
@@ -43,34 +43,17 @@ Gem::Specification.new do |s|
|
|
|
43
43
|
s.licenses = ["MIT"]
|
|
44
44
|
s.summary = "the ip2location ruby library"
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
end
|
|
46
|
+
s.metadata = {
|
|
47
|
+
"bug_tracker_uri" => "https://github.com/ip2location/ip2location-ruby/issues",
|
|
48
|
+
"documentation_uri" => "https://www.rubydoc.info/gems/ip2location_ruby",
|
|
49
|
+
"homepage_uri" => "https://www.ip2location.com",
|
|
50
|
+
"source_code_uri" => "https://github.com/ip2location/ip2location-ruby",
|
|
51
|
+
}
|
|
54
52
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
61
|
-
s.add_development_dependency(%q<rdoc>, [">= 6.3.1"])
|
|
62
|
-
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
|
63
|
-
else
|
|
64
|
-
s.add_dependency(%q<bindata>, ["~> 2.4.15"])
|
|
65
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
66
|
-
s.add_dependency(%q<rdoc>, [">= 6.3.1"])
|
|
67
|
-
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
|
68
|
-
end
|
|
69
|
-
else
|
|
70
|
-
s.add_dependency(%q<bindata>, ["~> 2.4.15"])
|
|
71
|
-
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
|
72
|
-
s.add_dependency(%q<rdoc>, [">= 6.3.1"])
|
|
73
|
-
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
|
74
|
-
end
|
|
53
|
+
s.required_ruby_version = ">= 3.0"
|
|
54
|
+
s.add_runtime_dependency "bindata", "~> 3.0"
|
|
55
|
+
s.add_development_dependency "rspec", "~> 3.13"
|
|
56
|
+
s.add_development_dependency "rdoc", ">= 6.3.1"
|
|
57
|
+
s.add_development_dependency "bundler", ">= 2.4"
|
|
75
58
|
end
|
|
76
59
|
|
|
@@ -23,7 +23,10 @@ class DbConfig
|
|
|
23
23
|
:CATEGORY => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 22, 22],
|
|
24
24
|
:DISTRICT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 23],
|
|
25
25
|
:ASN => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 24],
|
|
26
|
-
:AS => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25]
|
|
26
|
+
:AS => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 25],
|
|
27
|
+
:AS_DOMAIN => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26],
|
|
28
|
+
:AS_USAGETYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27],
|
|
29
|
+
:AS_CIDR => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28]
|
|
27
30
|
}
|
|
28
31
|
|
|
29
32
|
def self.setup_database(db_index)
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
class I2lStringData
|
|
2
|
-
|
|
1
|
+
class I2lStringData < BinData::BasePrimitive
|
|
3
2
|
def read_and_return_value(io)
|
|
4
3
|
country_long = eval_parameter(:country_long)
|
|
5
|
-
io.
|
|
6
|
-
|
|
4
|
+
raw_io = io.instance_variable_get(:@io)
|
|
5
|
+
initial_pos = raw_io.instance_variable_get(:@initial_pos)
|
|
6
|
+
if country_long
|
|
7
|
+
io.seek_to_abs_offset(raw_io.offset - 4)
|
|
8
|
+
end
|
|
7
9
|
addr = BinData::Uint32le.read(io)
|
|
8
|
-
old_offset =
|
|
9
|
-
country_long ?
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
old_offset = raw_io.offset
|
|
11
|
+
string_offset = country_long ? addr + 3 : addr
|
|
12
|
+
relative_offset = string_offset - initial_pos
|
|
13
|
+
io.seek_to_abs_offset(relative_offset)
|
|
14
|
+
length = BinData::Uint8.read(io)
|
|
15
|
+
result = BinData::String.new(:length => length).read(io)
|
|
16
|
+
io.seek_to_abs_offset(old_offset)
|
|
17
|
+
result
|
|
14
18
|
end
|
|
15
|
-
|
|
16
19
|
end
|
data/lib/ip2location_ruby.rb
CHANGED
|
@@ -14,7 +14,7 @@ require 'ip2location_ruby/ip2location_record'
|
|
|
14
14
|
class Ip2location
|
|
15
15
|
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday, :last_err_msg
|
|
16
16
|
|
|
17
|
-
VERSION = '8.
|
|
17
|
+
VERSION = '8.8.1'
|
|
18
18
|
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
|
19
19
|
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
|
|
20
20
|
INVALID_BIN_DATABASE = 'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
|
|
@@ -145,6 +145,9 @@ class Ip2location
|
|
|
145
145
|
district = IPV6_ADDRESS_IN_IPV4_BIN
|
|
146
146
|
asn = IPV6_ADDRESS_IN_IPV4_BIN
|
|
147
147
|
as = IPV6_ADDRESS_IN_IPV4_BIN
|
|
148
|
+
as_domain = IPV6_ADDRESS_IN_IPV4_BIN
|
|
149
|
+
as_usagetype = IPV6_ADDRESS_IN_IPV4_BIN
|
|
150
|
+
as_cidr = IPV6_ADDRESS_IN_IPV4_BIN
|
|
148
151
|
elsif !(rec.nil?)
|
|
149
152
|
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
|
150
153
|
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
|
@@ -171,6 +174,9 @@ class Ip2location
|
|
|
171
174
|
district = (defined?(rec.district) && rec.district != '') ? rec.district : FIELD_NOT_SUPPORTED
|
|
172
175
|
asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
|
|
173
176
|
as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
|
|
177
|
+
as_domain = (defined?(rec.as_domain) && rec.as_domain != '') ? rec.as_domain : FIELD_NOT_SUPPORTED
|
|
178
|
+
as_usagetype = (defined?(rec.as_usagetype) && rec.as_usagetype != '') ? rec.as_usagetype : FIELD_NOT_SUPPORTED
|
|
179
|
+
as_cidr = (defined?(rec.as_cidr) && rec.as_cidr != '') ? rec.as_cidr : FIELD_NOT_SUPPORTED
|
|
174
180
|
else
|
|
175
181
|
country_short = INVALID_IP_ADDRESS
|
|
176
182
|
country_long = INVALID_IP_ADDRESS
|
|
@@ -197,6 +203,9 @@ class Ip2location
|
|
|
197
203
|
district = INVALID_IP_ADDRESS
|
|
198
204
|
asn = INVALID_IP_ADDRESS
|
|
199
205
|
as = INVALID_IP_ADDRESS
|
|
206
|
+
as_domain = INVALID_IP_ADDRESS
|
|
207
|
+
as_usagetype = INVALID_IP_ADDRESS
|
|
208
|
+
as_cidr = INVALID_IP_ADDRESS
|
|
200
209
|
end
|
|
201
210
|
else
|
|
202
211
|
country_short = INVALID_IP_ADDRESS
|
|
@@ -224,6 +233,9 @@ class Ip2location
|
|
|
224
233
|
district = INVALID_IP_ADDRESS
|
|
225
234
|
asn = INVALID_IP_ADDRESS
|
|
226
235
|
as = INVALID_IP_ADDRESS
|
|
236
|
+
as_domain = INVALID_IP_ADDRESS
|
|
237
|
+
as_usagetype = INVALID_IP_ADDRESS
|
|
238
|
+
as_cidr = INVALID_IP_ADDRESS
|
|
227
239
|
end
|
|
228
240
|
results = {}
|
|
229
241
|
results['country_short'] = country_short
|
|
@@ -251,6 +263,9 @@ class Ip2location
|
|
|
251
263
|
results['district'] = district
|
|
252
264
|
results['asn'] = asn
|
|
253
265
|
results['as'] = as
|
|
266
|
+
results['as_domain'] = as_domain
|
|
267
|
+
results['as_usagetype'] = as_usagetype
|
|
268
|
+
results['as_cidr'] = as_cidr
|
|
254
269
|
return results
|
|
255
270
|
end
|
|
256
271
|
|
|
@@ -679,6 +694,57 @@ class Ip2location
|
|
|
679
694
|
return as
|
|
680
695
|
end
|
|
681
696
|
|
|
697
|
+
def get_as_domain(ip)
|
|
698
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
|
699
|
+
if valid
|
|
700
|
+
rec = get_record(ip)
|
|
701
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
|
702
|
+
as_domain = IPV6_ADDRESS_IN_IPV4_BIN
|
|
703
|
+
elsif !(rec.nil?)
|
|
704
|
+
as_domain = (defined?(rec.as_domain) && rec.as_domain != '') ? rec.as_domain : FIELD_NOT_SUPPORTED
|
|
705
|
+
else
|
|
706
|
+
as_domain = INVALID_IP_ADDRESS
|
|
707
|
+
end
|
|
708
|
+
else
|
|
709
|
+
as_domain = INVALID_IP_ADDRESS
|
|
710
|
+
end
|
|
711
|
+
return as_domain
|
|
712
|
+
end
|
|
713
|
+
|
|
714
|
+
def get_as_usagetype(ip)
|
|
715
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
|
716
|
+
if valid
|
|
717
|
+
rec = get_record(ip)
|
|
718
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
|
719
|
+
as_usagetype = IPV6_ADDRESS_IN_IPV4_BIN
|
|
720
|
+
elsif !(rec.nil?)
|
|
721
|
+
as_usagetype = (defined?(rec.as_usagetype) && rec.as_usagetype != '') ? rec.as_usagetype : FIELD_NOT_SUPPORTED
|
|
722
|
+
else
|
|
723
|
+
as_usagetype = INVALID_IP_ADDRESS
|
|
724
|
+
end
|
|
725
|
+
else
|
|
726
|
+
as_usagetype = INVALID_IP_ADDRESS
|
|
727
|
+
end
|
|
728
|
+
return as_usagetype
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
def get_as_cidr(ip)
|
|
732
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
|
733
|
+
if valid
|
|
734
|
+
rec = get_record(ip)
|
|
735
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
|
736
|
+
as_cidr = IPV6_ADDRESS_IN_IPV4_BIN
|
|
737
|
+
elsif !(rec.nil?)
|
|
738
|
+
as_cidr = (defined?(rec.as_cidr) && rec.as_cidr != '') ? rec.as_cidr : FIELD_NOT_SUPPORTED
|
|
739
|
+
else
|
|
740
|
+
as_cidr = INVALID_IP_ADDRESS
|
|
741
|
+
end
|
|
742
|
+
else
|
|
743
|
+
as_cidr = INVALID_IP_ADDRESS
|
|
744
|
+
end
|
|
745
|
+
return as_cidr
|
|
746
|
+
end
|
|
747
|
+
|
|
682
748
|
def bsearch(low, high, ipnum, base_addr, col_length)
|
|
683
749
|
while low <= high do
|
|
684
750
|
mid = (low + high) >> 1
|