ip2location_ruby 8.7.3 → 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/LICENSE.txt +1 -1
- data/VERSION +1 -1
- data/example.rb +3 -0
- data/ip2location_ruby.gemspec +1 -1
- data/lib/ip2location_ruby/database_config.rb +4 -1
- data/lib/ip2location_ruby.rb +67 -1
- data/spec/ip2location_ruby_database_spec.rb +18 -0
- data/spec/ip2location_ruby_iptools_spec.rb +1 -1
- metadata +3 -6
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/LICENSE.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
Copyright (c) 2023 -
|
1
|
+
Copyright (c) 2023 - 2025 IP2Location ( support@ip2location.com )
|
2
2
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
4
4
|
a copy of this software and associated documentation files (the
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.
|
1
|
+
8.8.0
|
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
@@ -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
@@ -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.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,14 +1,13 @@
|
|
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
|
@@ -113,7 +112,6 @@ metadata:
|
|
113
112
|
documentation_uri: https://www.rubydoc.info/gems/ip2location_ruby
|
114
113
|
homepage_uri: https://www.ip2location.com
|
115
114
|
source_code_uri: https://github.com/ip2location/ip2location-ruby
|
116
|
-
post_install_message:
|
117
115
|
rdoc_options: []
|
118
116
|
require_paths:
|
119
117
|
- lib
|
@@ -128,8 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
126
|
- !ruby/object:Gem::Version
|
129
127
|
version: '0'
|
130
128
|
requirements: []
|
131
|
-
rubygems_version: 3.
|
132
|
-
signing_key:
|
129
|
+
rubygems_version: 3.7.1
|
133
130
|
specification_version: 4
|
134
131
|
summary: the ip2location ruby library
|
135
132
|
test_files: []
|