ip2location_ruby 8.7.2 → 8.8.0
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 +1 -1
- data/LICENSE.txt +1 -1
- data/VERSION +1 -1
- data/example.rb +3 -6
- data/ip2location_ruby.gemspec +4 -5
- data/lib/ip2location_ruby/database_config.rb +4 -1
- data/lib/ip2location_ruby.rb +68 -2
- data/spec/ip2location_ruby_database_spec.rb +18 -0
- data/spec/ip2location_ruby_iptools_spec.rb +1 -1
- metadata +7 -11
- data/Gemfile.lock +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25bcf30ad8b3df703b3f9e60869c7bf3964caff22bb6a32c078e771ae4fcea8d
|
4
|
+
data.tar.gz: e59e3569acacb0d262ebf1de4114633a78529707b62c4aa8092cec7a58303930
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa3a4ffd3a2123780c3576e25d63c4fe7a9cb38d270c46e7995b94375614c6f02f5e99a7941f97ce03524d8e1988185373eb7f17b98fc51520fb88e0aee4ebcd
|
7
|
+
data.tar.gz: c0134ba082b34fc1a1340367b15c9783b1935cbf3c2488df4564d00d644afc1a04c1e6fff845790abe768c1341ef182054e5a02da558c4f6270d095a8ee73de9
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ 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', "~> 2.4.15"
|
6
6
|
# Add dependencies to develop your gem here.
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
|
data/LICENSE.txt
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.
|
1
|
+
8.8.0
|
data/example.rb
CHANGED
@@ -32,14 +32,11 @@ 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
|
-
# Web Service
|
38
|
-
ws = Ip2locationWebService.new('demo', 'WS25', true)
|
39
|
-
record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
|
40
|
-
puts record
|
41
|
-
puts ws.get_credit()
|
42
|
-
|
43
40
|
# IP Tools
|
44
41
|
iptool = Ip2locationIpTools.new()
|
45
42
|
puts iptool.is_ipv4('8.8.8.8')
|
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.0"
|
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"]
|
@@ -16,7 +16,6 @@ Gem::Specification.new do |s|
|
|
16
16
|
".document",
|
17
17
|
".rspec",
|
18
18
|
"Gemfile",
|
19
|
-
"Gemfile.lock",
|
20
19
|
"LICENSE.txt",
|
21
20
|
"Rakefile",
|
22
21
|
"VERSION",
|
@@ -57,18 +56,18 @@ Gem::Specification.new do |s|
|
|
57
56
|
s.specification_version = 4
|
58
57
|
|
59
58
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
60
|
-
s.add_runtime_dependency(%q<bindata>, ["
|
59
|
+
s.add_runtime_dependency(%q<bindata>, ["~> 2.4.15"])
|
61
60
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
61
|
s.add_development_dependency(%q<rdoc>, [">= 6.3.1"])
|
63
62
|
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
64
63
|
else
|
65
|
-
s.add_dependency(%q<bindata>, ["
|
64
|
+
s.add_dependency(%q<bindata>, ["~> 2.4.15"])
|
66
65
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
67
66
|
s.add_dependency(%q<rdoc>, [">= 6.3.1"])
|
68
67
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
69
68
|
end
|
70
69
|
else
|
71
|
-
s.add_dependency(%q<bindata>, ["
|
70
|
+
s.add_dependency(%q<bindata>, ["~> 2.4.15"])
|
72
71
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
73
72
|
s.add_dependency(%q<rdoc>, [">= 6.3.1"])
|
74
73
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
@@ -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)
|
data/lib/ip2location_ruby.rb
CHANGED
@@ -12,9 +12,9 @@ require 'ip2location_ruby/i2l_ip_data'
|
|
12
12
|
require 'ip2location_ruby/ip2location_record'
|
13
13
|
|
14
14
|
class Ip2location
|
15
|
-
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :
|
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.0'
|
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
|
@@ -157,6 +157,24 @@ describe "Ip2location" do
|
|
157
157
|
expect(record).to eq 'NOT SUPPORTED'
|
158
158
|
end
|
159
159
|
|
160
|
+
it "work correctly with get_as_domain" do
|
161
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
162
|
+
record = i2l.get_as_domain('8.8.8.8')
|
163
|
+
expect(record).to eq 'NOT SUPPORTED'
|
164
|
+
end
|
165
|
+
|
166
|
+
it "work correctly with get_as_usagetype" do
|
167
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
168
|
+
record = i2l.get_as_usagetype('8.8.8.8')
|
169
|
+
expect(record).to eq 'NOT SUPPORTED'
|
170
|
+
end
|
171
|
+
|
172
|
+
it "work correctly with get_as_cidr" do
|
173
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
174
|
+
record = i2l.get_as_cidr('8.8.8.8')
|
175
|
+
expect(record).to eq 'NOT SUPPORTED'
|
176
|
+
end
|
177
|
+
|
160
178
|
it "work correctly with ipv6" do
|
161
179
|
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
162
180
|
record = i2l.get_all('2001:4860:4860::8888')
|
@@ -74,7 +74,7 @@ describe "Ip2location" do
|
|
74
74
|
iptool = Ip2locationIpTools.new()
|
75
75
|
record = iptool.cidr_to_ipv6('2002::1234:abcd:ffff:c0a8:101/64')
|
76
76
|
expect(record).to include(
|
77
|
-
"ip_start"=>"2002:0000:0000:1234:
|
77
|
+
"ip_start"=>"2002:0000:0000:1234:0000:0000:0000:0000",
|
78
78
|
"ip_end"=>"2002:0000:0000:1234:ffff:ffff:ffff:ffff"
|
79
79
|
)
|
80
80
|
end
|
metadata
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip2location_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ip2location
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bindata
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - "~>"
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: 2.4.15
|
20
19
|
type: :runtime
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
25
|
+
version: 2.4.15
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: rspec
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,7 +81,6 @@ files:
|
|
82
81
|
- ".document"
|
83
82
|
- ".rspec"
|
84
83
|
- Gemfile
|
85
|
-
- Gemfile.lock
|
86
84
|
- LICENSE.txt
|
87
85
|
- README.md
|
88
86
|
- Rakefile
|
@@ -114,7 +112,6 @@ metadata:
|
|
114
112
|
documentation_uri: https://www.rubydoc.info/gems/ip2location_ruby
|
115
113
|
homepage_uri: https://www.ip2location.com
|
116
114
|
source_code_uri: https://github.com/ip2location/ip2location-ruby
|
117
|
-
post_install_message:
|
118
115
|
rdoc_options: []
|
119
116
|
require_paths:
|
120
117
|
- lib
|
@@ -129,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
126
|
- !ruby/object:Gem::Version
|
130
127
|
version: '0'
|
131
128
|
requirements: []
|
132
|
-
rubygems_version: 3.
|
133
|
-
signing_key:
|
129
|
+
rubygems_version: 3.7.1
|
134
130
|
specification_version: 4
|
135
131
|
summary: the ip2location ruby library
|
136
132
|
test_files: []
|
data/Gemfile.lock
DELETED
@@ -1,25 +0,0 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
bindata (2.4.10)
|
5
|
-
diff-lcs (1.1.3)
|
6
|
-
json (>= 2.3.0)
|
7
|
-
rdoc (>= 6.3.1)
|
8
|
-
json (~> 1.4)
|
9
|
-
rspec (2.8.0)
|
10
|
-
rspec-core (~> 2.8.0)
|
11
|
-
rspec-expectations (~> 2.8.0)
|
12
|
-
rspec-mocks (~> 2.8.0)
|
13
|
-
rspec-core (2.8.0)
|
14
|
-
rspec-expectations (2.8.0)
|
15
|
-
diff-lcs (~> 1.1.2)
|
16
|
-
rspec-mocks (2.8.0)
|
17
|
-
|
18
|
-
PLATFORMS
|
19
|
-
ruby
|
20
|
-
|
21
|
-
DEPENDENCIES
|
22
|
-
bindata
|
23
|
-
bundler (>= 1.2.0)
|
24
|
-
rdoc (>= 6.3.1)
|
25
|
-
rspec (~> 2.8.0)
|