ip2location_ruby 8.2.1 → 8.3.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 +0 -3
- data/Gemfile.lock +25 -74
- data/LICENSE.txt +1 -1
- data/README.md +9 -3
- data/Rakefile +0 -14
- data/VERSION +1 -1
- data/example.rb +3 -1
- data/ip2location_ruby.gemspec +4 -19
- data/lib/ip2location_ruby.rb +174 -24
- data/lib/ip2location_ruby/database_config.rb +21 -19
- data/lib/ip2location_ruby/ip2location_config.rb +11 -8
- data/rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN +0 -0
- data/spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN +0 -0
- data/spec/ip2location_ruby_database_spec.rb +159 -0
- data/spec/ip2location_ruby_webservice_spec.rb +15 -0
- data/spec/spec_helper.rb +1 -2
- metadata +5 -48
- data/spec/assets/DB24.DEMO4.BIN +0 -0
- data/spec/assets/DB24.DEMO6.BIN +0 -0
- data/spec/assets/IP-COUNTRY-SAMPLE.BIN +0 -0
- data/spec/ip2location_ruby_spec.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88ca0a0eeda11477542ff26e73d650ee4710fe53cefacfae2becdab77a60b296
|
4
|
+
data.tar.gz: b53da2a74fb4cbe4580d0745cee0b9be50b21dc45d63b7baf4fd2d94090380a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f20f7d2bb1fd83dacaacc4f78e9f2641a67be6a833be040c9ceaf289471d58658df35f01623bb8429bfaf9830df36e10517a693ab564c4542911c510f5b90292
|
7
|
+
data.tar.gz: b8f9340cd456e71a2e7920290f04aeea7d1d88692d53dee247f537f31b7ab25e5ccf83870667b5df626080c65a60c872ede67c606aab11dcdeef1d2cc7c5c4dd
|
data/Gemfile
CHANGED
@@ -7,10 +7,7 @@ gem 'bindata'
|
|
7
7
|
# Include everything needed to run rake, tests, features, etc.
|
8
8
|
|
9
9
|
group :development do
|
10
|
-
gem 'awesome_print'
|
11
10
|
gem "rspec", "~> 2.8.0"
|
12
11
|
gem "rdoc", "~> 3.12"
|
13
12
|
gem "bundler", ">= 1.2.0"
|
14
|
-
gem "jeweler", "~> 1.8.4"
|
15
|
-
gem "simplecov", ">= 0"
|
16
13
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,74 +1,25 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
git (>= 1.2.5)
|
27
|
-
github_api (= 0.10.1)
|
28
|
-
highline (>= 1.6.15)
|
29
|
-
nokogiri (>= 1.8.2)
|
30
|
-
rake
|
31
|
-
rdoc
|
32
|
-
json (1.8.1)
|
33
|
-
jwt (0.1.8)
|
34
|
-
multi_json (>= 1.5)
|
35
|
-
multi_json (1.8.2)
|
36
|
-
multi_xml (0.5.5)
|
37
|
-
multipart-post (1.2.0)
|
38
|
-
nokogiri (>= 1.8.2)
|
39
|
-
oauth2 (0.9.2)
|
40
|
-
faraday (~> 0.8)
|
41
|
-
httpauth (~> 0.2)
|
42
|
-
jwt (~> 0.1.4)
|
43
|
-
multi_json (~> 1.0)
|
44
|
-
multi_xml (~> 0.5)
|
45
|
-
rack (~> 1.2)
|
46
|
-
rack (>= 1.6.11)
|
47
|
-
rake (10.1.1)
|
48
|
-
rdoc (3.12.2)
|
49
|
-
json (~> 1.4)
|
50
|
-
rspec (2.8.0)
|
51
|
-
rspec-core (~> 2.8.0)
|
52
|
-
rspec-expectations (~> 2.8.0)
|
53
|
-
rspec-mocks (~> 2.8.0)
|
54
|
-
rspec-core (2.8.0)
|
55
|
-
rspec-expectations (2.8.0)
|
56
|
-
diff-lcs (~> 1.1.2)
|
57
|
-
rspec-mocks (2.8.0)
|
58
|
-
simplecov (0.8.2)
|
59
|
-
docile (~> 1.1.0)
|
60
|
-
multi_json
|
61
|
-
simplecov-html (~> 0.8.0)
|
62
|
-
simplecov-html (0.8.0)
|
63
|
-
|
64
|
-
PLATFORMS
|
65
|
-
ruby
|
66
|
-
|
67
|
-
DEPENDENCIES
|
68
|
-
awesome_print
|
69
|
-
bindata
|
70
|
-
bundler (>= 1.2.0)
|
71
|
-
jeweler (~> 1.8.4)
|
72
|
-
rdoc (~> 3.12)
|
73
|
-
rspec (~> 2.8.0)
|
74
|
-
simplecov
|
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 (3.12.2)
|
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 (~> 3.12)
|
25
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
[](https://rubygems.org/gems/ip2location_ruby)
|
3
3
|
|
4
4
|
# IP2Location Ruby Library
|
5
|
-
This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation,
|
5
|
+
This is IP2Location Ruby library that enables the user to find the country, region or state, city, latitude and longitude, US ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, usage type, IP address type and IAB advertising category from IP address using IP2Location database. The library reads the geo location information from **IP2Location BIN data** file or web service.
|
6
6
|
|
7
7
|
Supported IPv4 and IPv6 address.
|
8
8
|
|
@@ -19,6 +19,10 @@ Below is the description of the functions available in the **BIN Database** look
|
|
19
19
|
|---|---|
|
20
20
|
| open | Open the IP2Location BIN data for lookup. |
|
21
21
|
| close | Close and clean up the file pointer. |
|
22
|
+
| get_package_version | Get the package version (1 to 25 for DB1 to DB25 respectively). |
|
23
|
+
| get_module_version | Get the module version. |
|
24
|
+
| get_database_version | Get the database version. |
|
25
|
+
| get_last_error_message | Return the last error message. |
|
22
26
|
| get_all | Return the geolocation information in array. |
|
23
27
|
| get_country_short | Return the ISO3166-1 country code (2-digits) of the IP address. |
|
24
28
|
| get_country_long | Return the ISO3166-1 country name of the IP address. |
|
@@ -40,6 +44,8 @@ Below is the description of the functions available in the **BIN Database** look
|
|
40
44
|
| get_mobilebrand | Commercial brand associated with the mobile carrier. |
|
41
45
|
| get_elevation | Return average height of city above sea level in meters (m). |
|
42
46
|
| get_usagetype | Return the ISP's usage type of IP address. |
|
47
|
+
| get_addresstype | Returns the IP address type (A-Anycast, B-Broadcast, M-Multicast & U-Unicast) of IP address or domain name. |
|
48
|
+
| category | Returns the IAB content taxonomy category of IP address or domain name. |
|
43
49
|
|
44
50
|
|
45
51
|
## Web Service
|
@@ -47,8 +53,8 @@ Below is the description of the functions available in the **Web Service** looku
|
|
47
53
|
|
48
54
|
| Function Name | Description |
|
49
55
|
|---|---|
|
50
|
-
| Constructor | Expect 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 -
|
51
|
-
| lookup | Return the IP information in array.<ul><li>country_code</li><li>country_name</li><li>region_name</li><li>city_name</li><li>latitude</li><li>longitude</li><li>zip_code</li><li>time_zone</li><li>isp</li><li>domain</li><li>net_speed</li><li>idd_code</li><li>area_code</li><li>weather_station_code</li><li>weather_station_name</li><li>mcc</li><li>mnc</li><li>mobile_brand</li><li>elevation</li><li>usage_type</li><li>continent<ul><li>name</li><li>code</li><li>hemisphere</li><li>translations</li></ul></li><li>country<ul><li>name</li><li>alpha3_code</li><li>numeric_code</li><li>demonym</li><li>flag</li><li>capital</li><li>total_area</li><li>population</li><li>currency<ul><li>code</li><li>name</li><li>symbol</li></ul></li><li>language<ul><li>code</li><li>name</li></ul></li><li>idd_code</li><li>tld</li><li>translations</li></ul></li><li>region<ul><li>name</li><li>code</li><li>translations</li></ul></li><li>city<ul><li>name</li><li>translations</li></ul></li><li>geotargeting<ul><li>metro</li></ul></li><li>country_groupings</li><li>time_zone_info<ul><li>olson</li><li>current_time</li><li>gmt_offset</li><li>is_dst</li><li>sunrise</li><li>sunset</li></ul></li><ul> |
|
56
|
+
| Constructor | Expect 3 input parameters:<ol><li>IP2Location API Key.</li><li>Package (WS1 - WS25)</li></li><li>Use HTTPS or HTTP</li></ol> |
|
57
|
+
| lookup | Return the IP information in array.<ul><li>country_code</li><li>country_name</li><li>region_name</li><li>city_name</li><li>latitude</li><li>longitude</li><li>zip_code</li><li>time_zone</li><li>isp</li><li>domain</li><li>net_speed</li><li>idd_code</li><li>area_code</li><li>weather_station_code</li><li>weather_station_name</li><li>mcc</li><li>mnc</li><li>mobile_brand</li><li>elevation</li><li>usage_type</li><li>address_type</li><li>category</li><li>continent<ul><li>name</li><li>code</li><li>hemisphere</li><li>translations</li></ul></li><li>country<ul><li>name</li><li>alpha3_code</li><li>numeric_code</li><li>demonym</li><li>flag</li><li>capital</li><li>total_area</li><li>population</li><li>currency<ul><li>code</li><li>name</li><li>symbol</li></ul></li><li>language<ul><li>code</li><li>name</li></ul></li><li>idd_code</li><li>tld</li><li>translations</li></ul></li><li>region<ul><li>name</li><li>code</li><li>translations</li></ul></li><li>city<ul><li>name</li><li>translations</li></ul></li><li>geotargeting<ul><li>metro</li></ul></li><li>country_groupings</li><li>time_zone_info<ul><li>olson</li><li>current_time</li><li>gmt_offset</li><li>is_dst</li><li>sunrise</li><li>sunset</li></ul></li><ul> |
|
52
58
|
| get_credit | Return remaining credit of the web service account. |
|
53
59
|
|
54
60
|
# Dependencies
|
data/Rakefile
CHANGED
@@ -11,20 +11,6 @@ rescue Bundler::BundlerError => e
|
|
11
11
|
end
|
12
12
|
require 'rake'
|
13
13
|
|
14
|
-
require 'jeweler'
|
15
|
-
Jeweler::Tasks.new do |gem|
|
16
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
-
gem.name = "ip2location_ruby"
|
18
|
-
gem.homepage = "https://github.com/ip2location/ip2location-ruby"
|
19
|
-
gem.license = "MIT"
|
20
|
-
gem.summary = %Q{the ip2location ruby library}
|
21
|
-
gem.description = %Q{ip2location ruby library}
|
22
|
-
gem.email = "support@ip2location.com"
|
23
|
-
gem.authors = ["Vincent.Z"]
|
24
|
-
# dependencies defined in Gemfile
|
25
|
-
end
|
26
|
-
Jeweler::RubygemsDotOrgTasks.new
|
27
|
-
|
28
14
|
require 'rspec/core'
|
29
15
|
require 'rspec/core/rake_task'
|
30
16
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.
|
1
|
+
8.3.1
|
data/example.rb
CHANGED
@@ -30,11 +30,13 @@ print 'Elevation: '
|
|
30
30
|
print record['elevation']
|
31
31
|
print "\n"
|
32
32
|
print 'Usage Type: ' + record['usagetype'] + "\n"
|
33
|
+
print 'Address Type: ' + record['addresstype'] + "\n"
|
34
|
+
print 'Category: ' + record['category'] + "\n"
|
33
35
|
|
34
36
|
i2l.close()
|
35
37
|
|
36
38
|
# Web Service
|
37
|
-
ws = Ip2locationWebService.new('demo', '
|
39
|
+
ws = Ip2locationWebService.new('demo', 'WS25', true)
|
38
40
|
record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
|
39
41
|
print record
|
40
42
|
print "\n"
|
data/ip2location_ruby.gemspec
CHANGED
@@ -1,11 +1,6 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
-
# -*- encoding: utf-8 -*-
|
5
|
-
|
6
1
|
Gem::Specification.new do |s|
|
7
2
|
s.name = "ip2location_ruby"
|
8
|
-
s.version = "8.
|
3
|
+
s.version = "8.3.1"
|
9
4
|
|
10
5
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
6
|
s.require_paths = ["lib"]
|
@@ -34,10 +29,9 @@ Gem::Specification.new do |s|
|
|
34
29
|
"lib/ip2location_ruby/i2l_string_data.rb",
|
35
30
|
"lib/ip2location_ruby/ip2location_config.rb",
|
36
31
|
"lib/ip2location_ruby/ip2location_record.rb",
|
37
|
-
"spec/assets/
|
38
|
-
"spec/
|
39
|
-
"spec/
|
40
|
-
"spec/ip2location_ruby_spec.rb",
|
32
|
+
"spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN",
|
33
|
+
"spec/ip2location_ruby_database_spec.rb",
|
34
|
+
"spec/ip2location_ruby_webservice_spec.rb",
|
41
35
|
"spec/spec_helper.rb",
|
42
36
|
"rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN"
|
43
37
|
]
|
@@ -59,29 +53,20 @@ Gem::Specification.new do |s|
|
|
59
53
|
|
60
54
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
55
|
s.add_runtime_dependency(%q<bindata>, [">= 0"])
|
62
|
-
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
63
56
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
64
57
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
65
58
|
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
66
|
-
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
68
59
|
else
|
69
60
|
s.add_dependency(%q<bindata>, [">= 0"])
|
70
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
71
61
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
72
62
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
73
63
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
74
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
75
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
76
64
|
end
|
77
65
|
else
|
78
66
|
s.add_dependency(%q<bindata>, [">= 0"])
|
79
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
80
67
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
81
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
82
69
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
83
|
-
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
84
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
85
70
|
end
|
86
71
|
end
|
87
72
|
|
data/lib/ip2location_ruby.rb
CHANGED
@@ -11,16 +11,42 @@ require 'ip2location_ruby/i2l_ip_data'
|
|
11
11
|
require 'ip2location_ruby/ip2location_record'
|
12
12
|
|
13
13
|
class Ip2location
|
14
|
-
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr
|
14
|
+
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :count, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday, :last_err_msg
|
15
15
|
|
16
|
+
VERSION = '8.3.1'
|
16
17
|
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
17
18
|
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
|
19
|
+
INVALID_BIN_DATABASE = 'Incorrect IP2Location BIN file format. Please make sure that you are using the latest IP2Location BIN file.'
|
20
|
+
IPV6_ADDRESS_IN_IPV4_BIN = 'IPV6 ADDRESS MISSING IN IPV4 BIN'
|
18
21
|
|
19
22
|
def open(url)
|
20
|
-
|
23
|
+
if url == ''
|
24
|
+
self.last_err_msg = 'Ip2location.new.open() requires a database path name.'
|
25
|
+
abort('Ip2location.new.open() requires a database path name.')
|
26
|
+
end
|
27
|
+
|
28
|
+
begin
|
29
|
+
self.file = File.open(File.expand_path url, 'rb')
|
30
|
+
rescue
|
31
|
+
self.last_err_msg = 'Ip2location.new.open() error in opening ' + url +'.'
|
32
|
+
abort('Ip2location.new.open() error in opening ' + url +'.')
|
33
|
+
else
|
34
|
+
end
|
21
35
|
i2l = Ip2locationConfig.read(file)
|
36
|
+
if i2l.productcode == 1
|
37
|
+
else
|
38
|
+
if i2l.databaseyear <= 20 && i2l.productcode == 0
|
39
|
+
else
|
40
|
+
self.file.close
|
41
|
+
self.last_err_msg = INVALID_BIN_DATABASE
|
42
|
+
abort(INVALID_BIN_DATABASE)
|
43
|
+
end
|
44
|
+
end
|
22
45
|
self.db_index = i2l.databasetype
|
23
46
|
self.columns = i2l.databasecolumn + 0
|
47
|
+
self.databaseyear = 2000 + i2l.databaseyear
|
48
|
+
self.databasemonth = i2l.databasemonth
|
49
|
+
self.databaseday = i2l.databaseday
|
24
50
|
self.database = DbConfig.setup_database(self.db_index)
|
25
51
|
self.ipv4databasecount = i2l.ipv4databasecount
|
26
52
|
self.ipv4databaseaddr = i2l.ipv4databaseaddr
|
@@ -37,12 +63,31 @@ class Ip2location
|
|
37
63
|
self.file.close
|
38
64
|
end
|
39
65
|
|
66
|
+
def get_last_error_message()
|
67
|
+
return self.last_err_msg
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_module_version()
|
71
|
+
return VERSION
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_package_version()
|
75
|
+
return (self.db_index).to_s
|
76
|
+
end
|
77
|
+
|
78
|
+
def get_database_version()
|
79
|
+
return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s
|
80
|
+
end
|
81
|
+
|
40
82
|
def get_record(ip)
|
41
83
|
ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
|
42
84
|
self.ip_version, ipnum = validateip(ipno)
|
43
85
|
self.v4 = ip_version == 4 ? true : false
|
44
86
|
self.count = v4 ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
45
87
|
self.base_addr = (v4 ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
|
88
|
+
if ip_version == 6 && self.ipv6databasecount == 0
|
89
|
+
return IPV6_ADDRESS_IN_IPV4_BIN
|
90
|
+
end
|
46
91
|
col_length = columns * 4
|
47
92
|
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
48
93
|
indexpos = 0
|
@@ -74,7 +119,30 @@ class Ip2location
|
|
74
119
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
75
120
|
if valid
|
76
121
|
rec = get_record(ip)
|
77
|
-
if
|
122
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
123
|
+
country_short = IPV6_ADDRESS_IN_IPV4_BIN
|
124
|
+
country_long = IPV6_ADDRESS_IN_IPV4_BIN
|
125
|
+
region = IPV6_ADDRESS_IN_IPV4_BIN
|
126
|
+
city = IPV6_ADDRESS_IN_IPV4_BIN
|
127
|
+
latitude = IPV6_ADDRESS_IN_IPV4_BIN
|
128
|
+
longitude = IPV6_ADDRESS_IN_IPV4_BIN
|
129
|
+
isp = IPV6_ADDRESS_IN_IPV4_BIN
|
130
|
+
domain = IPV6_ADDRESS_IN_IPV4_BIN
|
131
|
+
netspeed = IPV6_ADDRESS_IN_IPV4_BIN
|
132
|
+
areacode = IPV6_ADDRESS_IN_IPV4_BIN
|
133
|
+
iddcode = IPV6_ADDRESS_IN_IPV4_BIN
|
134
|
+
timezone = IPV6_ADDRESS_IN_IPV4_BIN
|
135
|
+
zipcode = IPV6_ADDRESS_IN_IPV4_BIN
|
136
|
+
weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN
|
137
|
+
weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN
|
138
|
+
mcc = IPV6_ADDRESS_IN_IPV4_BIN
|
139
|
+
mnc = IPV6_ADDRESS_IN_IPV4_BIN
|
140
|
+
mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN
|
141
|
+
elevation = IPV6_ADDRESS_IN_IPV4_BIN
|
142
|
+
usagetype = IPV6_ADDRESS_IN_IPV4_BIN
|
143
|
+
addresstype = IPV6_ADDRESS_IN_IPV4_BIN
|
144
|
+
category = IPV6_ADDRESS_IN_IPV4_BIN
|
145
|
+
elsif !(rec.nil?)
|
78
146
|
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
79
147
|
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
80
148
|
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
@@ -95,6 +163,8 @@ class Ip2location
|
|
95
163
|
mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
|
96
164
|
elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
|
97
165
|
usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
|
166
|
+
addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED
|
167
|
+
category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED
|
98
168
|
else
|
99
169
|
country_short = INVALID_IP_ADDRESS
|
100
170
|
country_long = INVALID_IP_ADDRESS
|
@@ -116,6 +186,8 @@ class Ip2location
|
|
116
186
|
mobilebrand = INVALID_IP_ADDRESS
|
117
187
|
elevation = INVALID_IP_ADDRESS
|
118
188
|
usagetype = INVALID_IP_ADDRESS
|
189
|
+
addresstype = INVALID_IP_ADDRESS
|
190
|
+
category = INVALID_IP_ADDRESS
|
119
191
|
end
|
120
192
|
else
|
121
193
|
country_short = INVALID_IP_ADDRESS
|
@@ -138,6 +210,8 @@ class Ip2location
|
|
138
210
|
mobilebrand = INVALID_IP_ADDRESS
|
139
211
|
elevation = INVALID_IP_ADDRESS
|
140
212
|
usagetype = INVALID_IP_ADDRESS
|
213
|
+
addresstype = INVALID_IP_ADDRESS
|
214
|
+
category = INVALID_IP_ADDRESS
|
141
215
|
end
|
142
216
|
results = {}
|
143
217
|
results['country_short'] = country_short
|
@@ -160,6 +234,8 @@ class Ip2location
|
|
160
234
|
results['mobilebrand'] = mobilebrand
|
161
235
|
results['elevation'] = elevation
|
162
236
|
results['usagetype'] = usagetype
|
237
|
+
results['addresstype'] = addresstype
|
238
|
+
results['category'] = category
|
163
239
|
return results
|
164
240
|
end
|
165
241
|
|
@@ -167,7 +243,9 @@ class Ip2location
|
|
167
243
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
168
244
|
if valid
|
169
245
|
rec = get_record(ip)
|
170
|
-
if
|
246
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
247
|
+
country_short = IPV6_ADDRESS_IN_IPV4_BIN
|
248
|
+
elsif !(rec.nil?)
|
171
249
|
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
172
250
|
else
|
173
251
|
country_short = INVALID_IP_ADDRESS
|
@@ -182,7 +260,9 @@ class Ip2location
|
|
182
260
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
183
261
|
if valid
|
184
262
|
rec = get_record(ip)
|
185
|
-
if
|
263
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
264
|
+
country_long = IPV6_ADDRESS_IN_IPV4_BIN
|
265
|
+
elsif !(rec.nil?)
|
186
266
|
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
187
267
|
else
|
188
268
|
country_long = INVALID_IP_ADDRESS
|
@@ -197,7 +277,9 @@ class Ip2location
|
|
197
277
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
198
278
|
if valid
|
199
279
|
rec = get_record(ip)
|
200
|
-
if
|
280
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
281
|
+
region = IPV6_ADDRESS_IN_IPV4_BIN
|
282
|
+
elsif !(rec.nil?)
|
201
283
|
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
202
284
|
else
|
203
285
|
region = INVALID_IP_ADDRESS
|
@@ -212,7 +294,9 @@ class Ip2location
|
|
212
294
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
213
295
|
if valid
|
214
296
|
rec = get_record(ip)
|
215
|
-
if
|
297
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
298
|
+
city = IPV6_ADDRESS_IN_IPV4_BIN
|
299
|
+
elsif !(rec.nil?)
|
216
300
|
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
217
301
|
else
|
218
302
|
city = INVALID_IP_ADDRESS
|
@@ -227,7 +311,9 @@ class Ip2location
|
|
227
311
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
228
312
|
if valid
|
229
313
|
rec = get_record(ip)
|
230
|
-
if
|
314
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
315
|
+
latitude = IPV6_ADDRESS_IN_IPV4_BIN
|
316
|
+
elsif !(rec.nil?)
|
231
317
|
latitude = (defined?(rec.latitude) && rec.latitude != '') ? rec.latitude : FIELD_NOT_SUPPORTED
|
232
318
|
else
|
233
319
|
latitude = INVALID_IP_ADDRESS
|
@@ -242,7 +328,9 @@ class Ip2location
|
|
242
328
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
243
329
|
if valid
|
244
330
|
rec = get_record(ip)
|
245
|
-
if
|
331
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
332
|
+
longitude = IPV6_ADDRESS_IN_IPV4_BIN
|
333
|
+
elsif !(rec.nil?)
|
246
334
|
longitude = (defined?(rec.longitude) && rec.longitude != '') ? rec.longitude : FIELD_NOT_SUPPORTED
|
247
335
|
else
|
248
336
|
longitude = INVALID_IP_ADDRESS
|
@@ -257,7 +345,9 @@ class Ip2location
|
|
257
345
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
258
346
|
if valid
|
259
347
|
rec = get_record(ip)
|
260
|
-
if
|
348
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
349
|
+
isp = IPV6_ADDRESS_IN_IPV4_BIN
|
350
|
+
elsif !(rec.nil?)
|
261
351
|
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
262
352
|
else
|
263
353
|
isp = INVALID_IP_ADDRESS
|
@@ -272,7 +362,9 @@ class Ip2location
|
|
272
362
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
273
363
|
if valid
|
274
364
|
rec = get_record(ip)
|
275
|
-
if
|
365
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
366
|
+
domain = IPV6_ADDRESS_IN_IPV4_BIN
|
367
|
+
elsif !(rec.nil?)
|
276
368
|
domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED
|
277
369
|
else
|
278
370
|
domain = INVALID_IP_ADDRESS
|
@@ -287,7 +379,9 @@ class Ip2location
|
|
287
379
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
288
380
|
if valid
|
289
381
|
rec = get_record(ip)
|
290
|
-
if
|
382
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
383
|
+
zipcode = IPV6_ADDRESS_IN_IPV4_BIN
|
384
|
+
elsif !(rec.nil?)
|
291
385
|
zipcode = (defined?(rec.zipcode) && rec.zipcode != '') ? rec.zipcode : FIELD_NOT_SUPPORTED
|
292
386
|
else
|
293
387
|
zipcode = INVALID_IP_ADDRESS
|
@@ -302,7 +396,9 @@ class Ip2location
|
|
302
396
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
303
397
|
if valid
|
304
398
|
rec = get_record(ip)
|
305
|
-
if
|
399
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
400
|
+
timezone = IPV6_ADDRESS_IN_IPV4_BIN
|
401
|
+
elsif !(rec.nil?)
|
306
402
|
timezone = (defined?(rec.timezone) && rec.timezone != '') ? rec.timezone : FIELD_NOT_SUPPORTED
|
307
403
|
else
|
308
404
|
timezone = INVALID_IP_ADDRESS
|
@@ -317,7 +413,9 @@ class Ip2location
|
|
317
413
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
318
414
|
if valid
|
319
415
|
rec = get_record(ip)
|
320
|
-
if
|
416
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
417
|
+
netspeed = IPV6_ADDRESS_IN_IPV4_BIN
|
418
|
+
elsif !(rec.nil?)
|
321
419
|
netspeed = (defined?(rec.netspeed) && rec.netspeed != '') ? rec.netspeed : FIELD_NOT_SUPPORTED
|
322
420
|
else
|
323
421
|
netspeed = INVALID_IP_ADDRESS
|
@@ -332,7 +430,9 @@ class Ip2location
|
|
332
430
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
333
431
|
if valid
|
334
432
|
rec = get_record(ip)
|
335
|
-
if
|
433
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
434
|
+
iddcode = IPV6_ADDRESS_IN_IPV4_BIN
|
435
|
+
elsif !(rec.nil?)
|
336
436
|
iddcode = (defined?(rec.iddcode) && rec.iddcode != '') ? rec.iddcode : FIELD_NOT_SUPPORTED
|
337
437
|
else
|
338
438
|
iddcode = INVALID_IP_ADDRESS
|
@@ -347,7 +447,9 @@ class Ip2location
|
|
347
447
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
348
448
|
if valid
|
349
449
|
rec = get_record(ip)
|
350
|
-
if
|
450
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
451
|
+
areacode = IPV6_ADDRESS_IN_IPV4_BIN
|
452
|
+
elsif !(rec.nil?)
|
351
453
|
areacode = (defined?(rec.areacode) && rec.areacode != '') ? rec.areacode : FIELD_NOT_SUPPORTED
|
352
454
|
else
|
353
455
|
areacode = INVALID_IP_ADDRESS
|
@@ -362,7 +464,9 @@ class Ip2location
|
|
362
464
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
363
465
|
if valid
|
364
466
|
rec = get_record(ip)
|
365
|
-
if
|
467
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
468
|
+
weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN
|
469
|
+
elsif !(rec.nil?)
|
366
470
|
weatherstationcode = (defined?(rec.weatherstationcode) && rec.weatherstationcode != '') ? rec.weatherstationcode : FIELD_NOT_SUPPORTED
|
367
471
|
else
|
368
472
|
weatherstationcode = INVALID_IP_ADDRESS
|
@@ -377,7 +481,9 @@ class Ip2location
|
|
377
481
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
378
482
|
if valid
|
379
483
|
rec = get_record(ip)
|
380
|
-
if
|
484
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
485
|
+
weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN
|
486
|
+
elsif !(rec.nil?)
|
381
487
|
weatherstationname = (defined?(rec.weatherstationname) && rec.weatherstationname != '') ? rec.weatherstationname : FIELD_NOT_SUPPORTED
|
382
488
|
else
|
383
489
|
weatherstationname = INVALID_IP_ADDRESS
|
@@ -392,7 +498,9 @@ class Ip2location
|
|
392
498
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
393
499
|
if valid
|
394
500
|
rec = get_record(ip)
|
395
|
-
if
|
501
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
502
|
+
mcc = IPV6_ADDRESS_IN_IPV4_BIN
|
503
|
+
elsif !(rec.nil?)
|
396
504
|
mcc = (defined?(rec.mcc) && rec.mcc != '') ? rec.mcc : FIELD_NOT_SUPPORTED
|
397
505
|
else
|
398
506
|
mcc = INVALID_IP_ADDRESS
|
@@ -407,8 +515,10 @@ class Ip2location
|
|
407
515
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
408
516
|
if valid
|
409
517
|
rec = get_record(ip)
|
410
|
-
if
|
411
|
-
mnc =
|
518
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
519
|
+
mnc = IPV6_ADDRESS_IN_IPV4_BIN
|
520
|
+
elsif !(rec.nil?)
|
521
|
+
mnc = (defined?(rec.mnc) && rec.mnc != '') ? rec.mnc : FIELD_NOT_SUPPORTED
|
412
522
|
else
|
413
523
|
mnc = INVALID_IP_ADDRESS
|
414
524
|
end
|
@@ -422,7 +532,9 @@ class Ip2location
|
|
422
532
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
423
533
|
if valid
|
424
534
|
rec = get_record(ip)
|
425
|
-
if
|
535
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
536
|
+
mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN
|
537
|
+
elsif !(rec.nil?)
|
426
538
|
mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
|
427
539
|
else
|
428
540
|
mobilebrand = INVALID_IP_ADDRESS
|
@@ -437,7 +549,9 @@ class Ip2location
|
|
437
549
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
438
550
|
if valid
|
439
551
|
rec = get_record(ip)
|
440
|
-
if
|
552
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
553
|
+
elevation = IPV6_ADDRESS_IN_IPV4_BIN
|
554
|
+
elsif !(rec.nil?)
|
441
555
|
elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
|
442
556
|
else
|
443
557
|
elevation = INVALID_IP_ADDRESS
|
@@ -452,7 +566,9 @@ class Ip2location
|
|
452
566
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
453
567
|
if valid
|
454
568
|
rec = get_record(ip)
|
455
|
-
if
|
569
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
570
|
+
usagetype = IPV6_ADDRESS_IN_IPV4_BIN
|
571
|
+
elsif !(rec.nil?)
|
456
572
|
usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
|
457
573
|
else
|
458
574
|
usagetype = INVALID_IP_ADDRESS
|
@@ -463,6 +579,40 @@ class Ip2location
|
|
463
579
|
return usagetype
|
464
580
|
end
|
465
581
|
|
582
|
+
def get_addresstype(ip)
|
583
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
584
|
+
if valid
|
585
|
+
rec = get_record(ip)
|
586
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
587
|
+
addresstype = IPV6_ADDRESS_IN_IPV4_BIN
|
588
|
+
elsif !(rec.nil?)
|
589
|
+
addresstype = (defined?(rec.addresstype) && rec.addresstype != '') ? rec.addresstype : FIELD_NOT_SUPPORTED
|
590
|
+
else
|
591
|
+
addresstype = INVALID_IP_ADDRESS
|
592
|
+
end
|
593
|
+
else
|
594
|
+
addresstype = INVALID_IP_ADDRESS
|
595
|
+
end
|
596
|
+
return addresstype
|
597
|
+
end
|
598
|
+
|
599
|
+
def get_category(ip)
|
600
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
601
|
+
if valid
|
602
|
+
rec = get_record(ip)
|
603
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
604
|
+
category = IPV6_ADDRESS_IN_IPV4_BIN
|
605
|
+
elsif !(rec.nil?)
|
606
|
+
category = (defined?(rec.category) && rec.category != '') ? rec.category : FIELD_NOT_SUPPORTED
|
607
|
+
else
|
608
|
+
category = INVALID_IP_ADDRESS
|
609
|
+
end
|
610
|
+
else
|
611
|
+
category = INVALID_IP_ADDRESS
|
612
|
+
end
|
613
|
+
return category
|
614
|
+
end
|
615
|
+
|
466
616
|
def bsearch(low, high, ipnum, base_addr, col_length)
|
467
617
|
while low <= high do
|
468
618
|
mid = (low + high) >> 1
|
@@ -1,24 +1,26 @@
|
|
1
1
|
class DbConfig
|
2
2
|
COLUMNS = {
|
3
|
-
:COUNTRY => [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
4
|
-
:REGION => [0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3,
|
5
|
-
:CITY => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
6
|
-
:
|
7
|
-
:
|
8
|
-
:
|
9
|
-
:
|
10
|
-
:
|
11
|
-
:
|
12
|
-
:NETSPEED => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
13
|
-
:IDDCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
14
|
-
:AREACODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
15
|
-
:WEATHERSTATIONCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
16
|
-
:WEATHERSTATIONNAME => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
17
|
-
:MCC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
18
|
-
:MNC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
19
|
-
:MOBILEBRAND => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
20
|
-
:ELEVATION => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
21
|
-
:USAGETYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
3
|
+
:COUNTRY => [0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
|
4
|
+
:REGION => [0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
|
5
|
+
:CITY => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4],
|
6
|
+
:LATITUDE => [0, 0, 0, 0, 0, 5, 5, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5],
|
7
|
+
:LONGITUDE => [0, 0, 0, 0, 0, 6, 6, 0, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6],
|
8
|
+
:ZIPCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 7, 0, 7, 7, 7, 0, 7, 0, 7, 7, 7, 0, 7, 7],
|
9
|
+
:TIMEZONE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 7, 8, 8, 8, 7, 8, 0, 8, 8, 8, 0, 8, 8],
|
10
|
+
:ISP => [0, 0, 3, 0, 5, 0, 7, 5, 7, 0, 8, 0, 9, 0, 9, 0, 9, 0, 9, 7, 9, 0, 9, 7, 9, 9],
|
11
|
+
:DOMAIN => [0, 0, 0, 0, 0, 0, 0, 6, 8, 0, 9, 0, 10, 0, 10, 0, 10, 0, 10, 8, 10, 0, 10, 8, 10, 10],
|
12
|
+
:NETSPEED => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 11, 0, 11,8, 11, 0, 11, 0, 11, 0, 11, 11],
|
13
|
+
:IDDCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 12, 0, 12, 0, 12, 9, 12, 0, 12, 12],
|
14
|
+
:AREACODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10 ,13 ,0, 13, 0, 13, 10, 13, 0, 13, 13],
|
15
|
+
:WEATHERSTATIONCODE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 14, 0, 14, 0, 14, 0, 14, 14],
|
16
|
+
:WEATHERSTATIONNAME => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 15, 0, 15, 0, 15, 0, 15, 15],
|
17
|
+
:MCC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 16, 0, 16, 9, 16, 16],
|
18
|
+
:MNC => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10,17, 0, 17, 10, 17, 17],
|
19
|
+
:MOBILEBRAND => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11,18, 0, 18, 11, 18, 18],
|
20
|
+
:ELEVATION => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11, 19, 0, 19, 19],
|
21
|
+
:USAGETYPE => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 20, 20],
|
22
|
+
:ADDRESSTYPE => [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, 21],
|
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
|
}
|
23
25
|
|
24
26
|
def self.setup_database(db_index)
|
@@ -1,17 +1,20 @@
|
|
1
1
|
class Ip2locationConfig < BinData::Record
|
2
2
|
endian :little
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
3
|
+
uint8 :databasetype
|
4
|
+
uint8 :databasecolumn
|
5
|
+
uint8 :databaseyear
|
6
|
+
uint8 :databasemonth
|
7
|
+
uint8 :databaseday
|
8
|
+
# uint32 :databasecount
|
9
|
+
# uint32 :databaseaddr
|
10
|
+
# uint32 :ipversion
|
11
11
|
uint32 :ipv4databasecount
|
12
12
|
uint32 :ipv4databaseaddr
|
13
13
|
uint32 :ipv6databasecount
|
14
14
|
uint32 :ipv6databaseaddr
|
15
15
|
uint32 :ipv4indexbaseaddr
|
16
16
|
uint32 :ipv6indexbaseaddr
|
17
|
+
uint8 :productcode
|
18
|
+
uint8 :licensecode
|
19
|
+
uint32 :databasesize
|
17
20
|
end
|
Binary file
|
Binary file
|
@@ -0,0 +1,159 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ip2location" do
|
4
|
+
it "work correctly with ipv4" do
|
5
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
6
|
+
record = i2l.get_all('8.8.8.8')
|
7
|
+
expect(record['country_short']).to eq 'US'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "work correctly with get_country_short" do
|
11
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
12
|
+
record = i2l.get_country_short('8.8.8.8')
|
13
|
+
expect(record).to eq 'US'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "work correctly with get_country_long" do
|
17
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
18
|
+
record = i2l.get_country_long('8.8.8.8')
|
19
|
+
expect(record).to eq 'United States of America'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "work correctly with get_region" do
|
23
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
24
|
+
record = i2l.get_region('8.8.8.8')
|
25
|
+
expect(record).to eq 'NOT SUPPORTED'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "work correctly with get_city" do
|
29
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
30
|
+
record = i2l.get_city('8.8.8.8')
|
31
|
+
expect(record).to eq 'NOT SUPPORTED'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "work correctly with get_latitude" do
|
35
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
36
|
+
record = i2l.get_latitude('8.8.8.8')
|
37
|
+
expect(record).to eq 'NOT SUPPORTED'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "work correctly with get_longitude" do
|
41
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
42
|
+
record = i2l.get_longitude('8.8.8.8')
|
43
|
+
expect(record).to eq 'NOT SUPPORTED'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "work correctly with get_isp" do
|
47
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
48
|
+
record = i2l.get_isp('8.8.8.8')
|
49
|
+
expect(record).to eq 'NOT SUPPORTED'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "work correctly with get_domain" do
|
53
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
54
|
+
record = i2l.get_domain('8.8.8.8')
|
55
|
+
expect(record).to eq 'NOT SUPPORTED'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "work correctly with get_zipcode" do
|
59
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
60
|
+
record = i2l.get_zipcode('8.8.8.8')
|
61
|
+
expect(record).to eq 'NOT SUPPORTED'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "work correctly with get_timezone" do
|
65
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
66
|
+
record = i2l.get_timezone('8.8.8.8')
|
67
|
+
expect(record).to eq 'NOT SUPPORTED'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "work correctly with get_netspeed" do
|
71
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
72
|
+
record = i2l.get_netspeed('8.8.8.8')
|
73
|
+
expect(record).to eq 'NOT SUPPORTED'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "work correctly with get_iddcode" do
|
77
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
78
|
+
record = i2l.get_iddcode('8.8.8.8')
|
79
|
+
expect(record).to eq 'NOT SUPPORTED'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "work correctly with get_areacode" do
|
83
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
84
|
+
record = i2l.get_areacode('8.8.8.8')
|
85
|
+
expect(record).to eq 'NOT SUPPORTED'
|
86
|
+
end
|
87
|
+
|
88
|
+
it "work correctly with get_weatherstationcode" do
|
89
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
90
|
+
record = i2l.get_weatherstationcode('8.8.8.8')
|
91
|
+
expect(record).to eq 'NOT SUPPORTED'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "work correctly with get_weatherstationname" do
|
95
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
96
|
+
record = i2l.get_weatherstationname('8.8.8.8')
|
97
|
+
expect(record).to eq 'NOT SUPPORTED'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "work correctly with get_mcc" do
|
101
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
102
|
+
record = i2l.get_mcc('8.8.8.8')
|
103
|
+
expect(record).to eq 'NOT SUPPORTED'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "work correctly with get_mnc" do
|
107
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
108
|
+
record = i2l.get_mnc('8.8.8.8')
|
109
|
+
expect(record).to eq 'NOT SUPPORTED'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "work correctly with get_mobilebrand" do
|
113
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
114
|
+
record = i2l.get_mobilebrand('8.8.8.8')
|
115
|
+
expect(record).to eq 'NOT SUPPORTED'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "work correctly with get_elevation" do
|
119
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
120
|
+
record = i2l.get_elevation('8.8.8.8')
|
121
|
+
expect(record).to eq 'NOT SUPPORTED'
|
122
|
+
end
|
123
|
+
|
124
|
+
it "work correctly with get_usagetype" do
|
125
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
126
|
+
record = i2l.get_usagetype('8.8.8.8')
|
127
|
+
expect(record).to eq 'NOT SUPPORTED'
|
128
|
+
end
|
129
|
+
|
130
|
+
it "work correctly with get_addresstype" do
|
131
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
132
|
+
record = i2l.get_addresstype('8.8.8.8')
|
133
|
+
expect(record).to eq 'NOT SUPPORTED'
|
134
|
+
end
|
135
|
+
|
136
|
+
it "work correctly with get_category" do
|
137
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
138
|
+
record = i2l.get_category('8.8.8.8')
|
139
|
+
expect(record).to eq 'NOT SUPPORTED'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "work correctly with ipv6" do
|
143
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
144
|
+
record = i2l.get_all('2001:4860:4860::8888')
|
145
|
+
expect(record['country_short']).to eq 'US'
|
146
|
+
end
|
147
|
+
|
148
|
+
it "work correctly with ipv6 get_country_long" do
|
149
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
150
|
+
record = i2l.get_country_long('2001:4860:4860::8888')
|
151
|
+
expect(record).to eq 'United States of America'
|
152
|
+
end
|
153
|
+
|
154
|
+
it "work correctly with ipv6 get_region" do
|
155
|
+
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
156
|
+
record = i2l.get_region('2001:4860:4860::8888')
|
157
|
+
expect(record).to eq 'NOT SUPPORTED'
|
158
|
+
end
|
159
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ip2location" do
|
4
|
+
it "work correctly with web service lookup" do
|
5
|
+
ws = Ip2locationWebService.new('demo', 'WS25', true)
|
6
|
+
record = ws.lookup('8.8.8.8', '', 'en')
|
7
|
+
expect(record['country_code']).to eq 'US'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "work correctly with web service get_credit" do
|
11
|
+
ws = Ip2locationWebService.new('demo', 'WS25', true)
|
12
|
+
record = ws.get_credit()
|
13
|
+
expect(record).to_not eq 0
|
14
|
+
end
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip2location_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 8.
|
4
|
+
version: 8.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ip2location
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: awesome_print
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,34 +66,6 @@ dependencies:
|
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: 1.2.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: jeweler
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 1.8.4
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 1.8.4
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: simplecov
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - ">="
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0'
|
111
69
|
description: The official IP2Location Ruby library to geolocate an IP address. You
|
112
70
|
can lookup for country, region, city, latitude, longitude, zip code, time zone,
|
113
71
|
ISP, domain, area code, usage type, mobile data, weather data and elevation from
|
@@ -137,10 +95,9 @@ files:
|
|
137
95
|
- lib/ip2location_ruby/ip2location_config.rb
|
138
96
|
- lib/ip2location_ruby/ip2location_record.rb
|
139
97
|
- rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN
|
140
|
-
- spec/assets/
|
141
|
-
- spec/
|
142
|
-
- spec/
|
143
|
-
- spec/ip2location_ruby_spec.rb
|
98
|
+
- spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN
|
99
|
+
- spec/ip2location_ruby_database_spec.rb
|
100
|
+
- spec/ip2location_ruby_webservice_spec.rb
|
144
101
|
- spec/spec_helper.rb
|
145
102
|
homepage: https://github.com/ip2location/ip2location-ruby
|
146
103
|
licenses:
|
data/spec/assets/DB24.DEMO4.BIN
DELETED
Binary file
|
data/spec/assets/DB24.DEMO6.BIN
DELETED
Binary file
|
Binary file
|
@@ -1,53 +0,0 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Ip2location" do
|
4
|
-
it "work correctly with ipv4" do
|
5
|
-
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP-COUNTRY-SAMPLE.bin")
|
6
|
-
record = i2l.get_all('13.5.10.6')
|
7
|
-
record.should_not be_nil
|
8
|
-
record.country_short.should == 'US'
|
9
|
-
end
|
10
|
-
|
11
|
-
it "work correctly with ipv4 with new library" do
|
12
|
-
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/DB24.DEMO4.bin")
|
13
|
-
record = i2l.get_all('13.5.10.6')
|
14
|
-
record.should_not be_nil
|
15
|
-
record.country_short.should == 'KR'
|
16
|
-
end
|
17
|
-
|
18
|
-
it "work correctly with ipv6 with new library" do
|
19
|
-
i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/DB24.DEMO6.bin")
|
20
|
-
record = i2l.get_all('2a01:04f8:0d16:26c2::')
|
21
|
-
record.should_not be_nil
|
22
|
-
record.country_short.should == 'DE'
|
23
|
-
end
|
24
|
-
|
25
|
-
# it "profile ipv6 in IPV6.BIN" do
|
26
|
-
# i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
|
27
|
-
# File.new(File.dirname(__FILE__) + "/assets/ipv6_ip.txt").readlines.each do |line|
|
28
|
-
# record = i2l.get_all(line.split(' ').first)
|
29
|
-
# end
|
30
|
-
# end
|
31
|
-
|
32
|
-
# it "profile ipv4 in IPV6.BIN" do
|
33
|
-
# i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IPV6-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
|
34
|
-
# File.new(File.dirname(__FILE__) + "/assets/ipv4_ip.txt").readlines.each do |line|
|
35
|
-
# record = i2l.get_all(line.split(' ').first)
|
36
|
-
# end
|
37
|
-
# end
|
38
|
-
|
39
|
-
# it "profile ipv4 in IPV4.BIN" do
|
40
|
-
# i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP-COUNTRY-REGION-CITY-LATITUDE-LONGITUDE-ZIPCODE-TIMEZONE-ISP-DOMAIN-NETSPEED-AREACODE-WEATHER-MOBILE-ELEVATION-USAGETYPE.BIN")
|
41
|
-
# File.new(File.dirname(__FILE__) + "/assets/ipv4_ip.txt").readlines.each do |line|
|
42
|
-
# record = i2l.get_all(line.split(' ').first)
|
43
|
-
# end
|
44
|
-
# end
|
45
|
-
|
46
|
-
# this need spec/assets/IP2LOCATION-LITE-DB5.bin file which too big to include in this test.
|
47
|
-
|
48
|
-
# it "should get float value of attitude" do
|
49
|
-
# i2l = Ip2location.new.open(File.dirname(__FILE__) + "/assets/IP2LOCATION-LITE-DB5.bin")
|
50
|
-
# record = i2l.get_all('192.110.164.88')
|
51
|
-
# record['latitude'].should eq(33.44837951660156)
|
52
|
-
# end
|
53
|
-
end
|