ip2location_ruby 8.1.1 → 8.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -2
- data/Gemfile.lock +66 -74
- data/LICENSE.txt +1 -1
- data/README.md +50 -38
- data/VERSION +1 -1
- data/example.rb +11 -1
- data/ip2location_ruby.gemspec +4 -11
- data/lib/ip2location_ruby.rb +226 -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 -34
- 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: e745f1d50bac46096d52e3b092873502999f28659108f701221225a015038865
|
4
|
+
data.tar.gz: 867a13f878805690873255278b61b03d554a143108fa099ccbbac3048808e0e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 569481b686f7ba1895982a6ccb38f77550df6406fe1e4dba889e6a425f01bf5db22c67abe58ea4e67e9d49c69cb96d23ab347b25be65f254ba8c0aebca700b84
|
7
|
+
data.tar.gz: 11721c250f7ed16ffb89c681678dc03a0eb39090857d85e38400e806399e9fae429738b686422208aa87ca81dcd134a049d35a83c5d1511158e7db46cec22bed
|
data/Gemfile
CHANGED
@@ -7,10 +7,8 @@ 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
13
|
gem "jeweler", "~> 1.8.4"
|
15
|
-
gem "simplecov", ">= 0"
|
16
14
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,74 +1,66 @@
|
|
1
|
-
GEM
|
2
|
-
remote: http://rubygems.org/
|
3
|
-
specs:
|
4
|
-
addressable (2.3.5)
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
rspec-
|
52
|
-
rspec-
|
53
|
-
|
54
|
-
rspec-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
+
addressable (2.3.5)
|
5
|
+
bindata (2.1.0)
|
6
|
+
builder (3.2.2)
|
7
|
+
diff-lcs (1.1.3)
|
8
|
+
docile (1.1.1)
|
9
|
+
faraday (0.8.8)
|
10
|
+
multipart-post (~> 1.2.0)
|
11
|
+
git (1.2.6)
|
12
|
+
github_api (0.10.1)
|
13
|
+
addressable
|
14
|
+
faraday (~> 0.8.1)
|
15
|
+
hashie (>= 1.2)
|
16
|
+
multi_json (~> 1.4)
|
17
|
+
nokogiri (~> 1.5.2)
|
18
|
+
oauth2
|
19
|
+
hashie (2.0.5)
|
20
|
+
highline (1.6.20)
|
21
|
+
httpauth (0.2.0)
|
22
|
+
jeweler (1.8.8)
|
23
|
+
builder
|
24
|
+
bundler (~> 1.0)
|
25
|
+
git (>= 1.2.5)
|
26
|
+
github_api (= 0.10.1)
|
27
|
+
highline (>= 1.6.15)
|
28
|
+
nokogiri (>= 1.8.2)
|
29
|
+
rake
|
30
|
+
rdoc
|
31
|
+
json (>= 2.3.0)
|
32
|
+
jwt (0.1.8)
|
33
|
+
multi_json (>= 1.5)
|
34
|
+
multi_json (1.8.2)
|
35
|
+
multi_xml (0.5.5)
|
36
|
+
multipart-post (1.2.0)
|
37
|
+
nokogiri (>= 1.8.2)
|
38
|
+
oauth2 (0.9.2)
|
39
|
+
faraday (~> 0.8)
|
40
|
+
httpauth (~> 0.2)
|
41
|
+
jwt (~> 0.1.4)
|
42
|
+
multi_json (~> 1.0)
|
43
|
+
multi_xml (~> 0.5)
|
44
|
+
rack (~> 1.2)
|
45
|
+
rack (>= 1.6.11)
|
46
|
+
rake (>= 12.3.3)
|
47
|
+
rdoc (3.12.2)
|
48
|
+
json (~> 1.4)
|
49
|
+
rspec (2.8.0)
|
50
|
+
rspec-core (~> 2.8.0)
|
51
|
+
rspec-expectations (~> 2.8.0)
|
52
|
+
rspec-mocks (~> 2.8.0)
|
53
|
+
rspec-core (2.8.0)
|
54
|
+
rspec-expectations (2.8.0)
|
55
|
+
diff-lcs (~> 1.1.2)
|
56
|
+
rspec-mocks (2.8.0)
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bindata
|
63
|
+
bundler (>= 1.2.0)
|
64
|
+
jeweler (~> 1.8.4)
|
65
|
+
rdoc (~> 3.12)
|
66
|
+
rspec (~> 2.8.0)
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
[![Total Downloads](https://img.shields.io/gem/dt/ip2location_ruby.svg)](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,
|
6
|
-
from **IP2Location BIN data** file.
|
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.
|
7
6
|
|
8
7
|
Supported IPv4 and IPv6 address.
|
9
8
|
|
@@ -11,50 +10,63 @@ For more details, please visit:
|
|
11
10
|
[https://www.ip2location.com/developers/ruby](https://www.ip2location.com/developers/ruby)
|
12
11
|
|
13
12
|
# Usage
|
13
|
+
You can check the **example.rb** file to learn more about usage.
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
## BIN Database
|
16
|
+
Below is the description of the functions available in the **BIN Database** lookup.
|
17
17
|
|
18
|
-
|
19
|
-
|
18
|
+
| Function Name | Description |
|
19
|
+
|---|---|
|
20
|
+
| open | Open the IP2Location BIN data for lookup. |
|
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. |
|
26
|
+
| get_all | Return the geolocation information in array. |
|
27
|
+
| get_country_short | Return the ISO3166-1 country code (2-digits) of the IP address. |
|
28
|
+
| get_country_long | Return the ISO3166-1 country name of the IP address. |
|
29
|
+
| get_region | Return the ISO3166-2 region name of the IP address. Please visit [ISO3166-2 Subdivision Code](https://www.ip2location.com/free/iso3166-2) for the information of ISO3166-2 supported |
|
30
|
+
| get_city | Return the city name of the IP address. |
|
31
|
+
| get_latitude | Return the city latitude of the IP address. |
|
32
|
+
| get_longitude | Return the city longtitude of the IP address. |
|
33
|
+
| get_isp | Return the ISP name of the IP address. |
|
34
|
+
| get_domain | Return the domain name of IP address. |
|
35
|
+
| get_zipcode | Return the zipcode of the city. |
|
36
|
+
| get_timezone | Return the UTC time zone (with DST supported). |
|
37
|
+
| get_netspeed | Return the Internet connection type. |
|
38
|
+
| get_iddcode | Return the IDD prefix to call the city from another country. |
|
39
|
+
| get_areacode | Return the area code of the city. |
|
40
|
+
| get_weathercode | Return the nearest weather observation station code. |
|
41
|
+
| get_weathername | Return the nearest weather observation station name. |
|
42
|
+
| get_mcc | Return the Mobile Country Codes (MCC). |
|
43
|
+
| get_mnc | Return the Mobile Network Code (MNC). |
|
44
|
+
| get_mobilebrand | Commercial brand associated with the mobile carrier. |
|
45
|
+
| get_elevation | Return average height of city above sea level in meters (m). |
|
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. |
|
20
49
|
|
21
|
-
print 'Country Code: ' + record['country_short'] + "\n"
|
22
|
-
print 'Country Name: ' + record['country_long'] + "\n"
|
23
|
-
print 'Region Name: ' + record['region'] + "\n"
|
24
|
-
print 'City Name: ' + record['city'] + "\n"
|
25
|
-
print 'Latitude: '
|
26
|
-
print record['latitude']
|
27
|
-
print "\n"
|
28
|
-
print 'Longitude: '
|
29
|
-
print record['longitude']
|
30
|
-
print "\n"
|
31
|
-
print 'ISP: ' + record['isp'] + "\n"
|
32
|
-
print 'Domain: ' + record['domain'] + "\n"
|
33
|
-
print 'Net Speed: ' + record['netspeed'] + "\n"
|
34
|
-
print 'Area Code: ' + record['areacode'] + "\n"
|
35
|
-
print 'IDD Code: ' + record['iddcode'] + "\n"
|
36
|
-
print 'Time Zone: ' + record['timezone'] + "\n"
|
37
|
-
print 'ZIP Code: ' + record['zipcode'] + "\n"
|
38
|
-
print 'Weather Station Code: ' + record['weatherstationname'] + "\n"
|
39
|
-
print 'Weather Station Name: ' + record['weatherstationcode'] + "\n"
|
40
|
-
print 'MCC: ' + record['mcc'] + "\n"
|
41
|
-
print 'MNC: ' + record['mnc'] + "\n"
|
42
|
-
print 'Mobile Name: ' + record['mobilebrand'] + "\n"
|
43
|
-
print 'Elevation: '
|
44
|
-
print record['elevation']
|
45
|
-
print "\n"
|
46
|
-
print 'Usage Type: ' + record['usagetype'] + "\n"
|
47
50
|
|
48
|
-
|
49
|
-
|
51
|
+
## Web Service
|
52
|
+
Below is the description of the functions available in the **Web Service** lookup.
|
50
53
|
|
51
|
-
|
54
|
+
| Function Name | Description |
|
55
|
+
|---|---|
|
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> |
|
58
|
+
| get_credit | Return remaining credit of the web service account. |
|
52
59
|
|
53
|
-
|
54
|
-
|
60
|
+
# Dependencies
|
61
|
+
This library requires IP2Location BIN data file to function. You may download the BIN data file at
|
62
|
+
* IP2Location LITE BIN Data (Free): https://lite.ip2location.com
|
63
|
+
* IP2Location Commercial BIN Data (Comprehensive): https://www.ip2location.com
|
55
64
|
|
56
|
-
|
65
|
+
An outdated BIN database was provided in the library for your testing. You are recommended to visit the above links to download the latest BIN database.
|
66
|
+
|
67
|
+
You can also sign up for [IP2Location Web Service](https://www.ip2location.com/web-service/ip2location) to lookup by IP2Location API.
|
57
68
|
|
69
|
+
# IPv4 BIN vs IPv6 BIN
|
58
70
|
* Use the IPv4 BIN file if you just need to query IPv4 addresses.
|
59
71
|
* Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
|
60
72
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
8.
|
1
|
+
8.3.0
|
data/example.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'ip2location_ruby'
|
2
2
|
|
3
|
+
# BIN Database
|
3
4
|
i2l = Ip2location.new.open("./data/IP2LOCATION-LITE-DB1.IPV6.BIN")
|
4
5
|
record = i2l.get_all('8.8.8.8')
|
5
6
|
|
@@ -29,5 +30,14 @@ print 'Elevation: '
|
|
29
30
|
print record['elevation']
|
30
31
|
print "\n"
|
31
32
|
print 'Usage Type: ' + record['usagetype'] + "\n"
|
33
|
+
print 'Address Type: ' + record['addresstype'] + "\n"
|
34
|
+
print 'Category: ' + record['category'] + "\n"
|
32
35
|
|
33
|
-
i2l.close()
|
36
|
+
i2l.close()
|
37
|
+
|
38
|
+
# Web Service
|
39
|
+
ws = Ip2locationWebService.new('demo', 'WS25', true)
|
40
|
+
record = ws.lookup('8.8.8.8', 'continent,country,region,city,geotargeting,country_groupings,time_zone_info', 'en')
|
41
|
+
print record
|
42
|
+
print "\n"
|
43
|
+
print ws.get_credit()
|
data/ip2location_ruby.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "ip2location_ruby"
|
8
|
-
s.version = "8.
|
8
|
+
s.version = "8.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.require_paths = ["lib"]
|
@@ -34,10 +34,9 @@ Gem::Specification.new do |s|
|
|
34
34
|
"lib/ip2location_ruby/i2l_string_data.rb",
|
35
35
|
"lib/ip2location_ruby/ip2location_config.rb",
|
36
36
|
"lib/ip2location_ruby/ip2location_record.rb",
|
37
|
-
"spec/assets/
|
38
|
-
"spec/
|
39
|
-
"spec/
|
40
|
-
"spec/ip2location_ruby_spec.rb",
|
37
|
+
"spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN",
|
38
|
+
"spec/ip2location_ruby_database_spec.rb",
|
39
|
+
"spec/ip2location_ruby_webservice_spec.rb",
|
41
40
|
"spec/spec_helper.rb",
|
42
41
|
"rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN"
|
43
42
|
]
|
@@ -59,29 +58,23 @@ Gem::Specification.new do |s|
|
|
59
58
|
|
60
59
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
61
60
|
s.add_runtime_dependency(%q<bindata>, [">= 0"])
|
62
|
-
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
63
61
|
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
64
62
|
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
65
63
|
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
66
64
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
67
|
-
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
68
65
|
else
|
69
66
|
s.add_dependency(%q<bindata>, [">= 0"])
|
70
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
71
67
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
72
68
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
73
69
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
74
70
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
75
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
76
71
|
end
|
77
72
|
else
|
78
73
|
s.add_dependency(%q<bindata>, [">= 0"])
|
79
|
-
s.add_dependency(%q<awesome_print>, [">= 0"])
|
80
74
|
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
81
75
|
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
82
76
|
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
83
77
|
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
84
|
-
s.add_dependency(%q<simplecov>, [">= 0"])
|
85
78
|
end
|
86
79
|
end
|
87
80
|
|
data/lib/ip2location_ruby.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require 'bindata'
|
3
3
|
require 'ipaddr'
|
4
|
+
require 'net/http'
|
5
|
+
require 'json'
|
4
6
|
require 'ip2location_ruby/ip2location_config'
|
5
7
|
require 'ip2location_ruby/database_config'
|
6
8
|
require 'ip2location_ruby/i2l_float_data'
|
@@ -9,16 +11,42 @@ require 'ip2location_ruby/i2l_ip_data'
|
|
9
11
|
require 'ip2location_ruby/ip2location_record'
|
10
12
|
|
11
13
|
class Ip2location
|
12
|
-
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
|
13
15
|
|
16
|
+
VERSION = '8.3.0'
|
14
17
|
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
15
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'
|
16
21
|
|
17
22
|
def open(url)
|
18
|
-
|
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
|
19
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
|
20
45
|
self.db_index = i2l.databasetype
|
21
46
|
self.columns = i2l.databasecolumn + 0
|
47
|
+
self.databaseyear = 2000 + i2l.databaseyear
|
48
|
+
self.databasemonth = i2l.databasemonth
|
49
|
+
self.databaseday = i2l.databaseday
|
22
50
|
self.database = DbConfig.setup_database(self.db_index)
|
23
51
|
self.ipv4databasecount = i2l.ipv4databasecount
|
24
52
|
self.ipv4databaseaddr = i2l.ipv4databaseaddr
|
@@ -35,12 +63,31 @@ class Ip2location
|
|
35
63
|
self.file.close
|
36
64
|
end
|
37
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
|
+
|
38
82
|
def get_record(ip)
|
39
83
|
ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
|
40
84
|
self.ip_version, ipnum = validateip(ipno)
|
41
85
|
self.v4 = ip_version == 4 ? true : false
|
42
86
|
self.count = v4 ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
43
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
|
44
91
|
col_length = columns * 4
|
45
92
|
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
46
93
|
indexpos = 0
|
@@ -72,7 +119,30 @@ class Ip2location
|
|
72
119
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
73
120
|
if valid
|
74
121
|
rec = get_record(ip)
|
75
|
-
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?)
|
76
146
|
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
77
147
|
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
78
148
|
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
@@ -93,6 +163,8 @@ class Ip2location
|
|
93
163
|
mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
|
94
164
|
elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
|
95
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
|
96
168
|
else
|
97
169
|
country_short = INVALID_IP_ADDRESS
|
98
170
|
country_long = INVALID_IP_ADDRESS
|
@@ -114,6 +186,8 @@ class Ip2location
|
|
114
186
|
mobilebrand = INVALID_IP_ADDRESS
|
115
187
|
elevation = INVALID_IP_ADDRESS
|
116
188
|
usagetype = INVALID_IP_ADDRESS
|
189
|
+
addresstype = INVALID_IP_ADDRESS
|
190
|
+
category = INVALID_IP_ADDRESS
|
117
191
|
end
|
118
192
|
else
|
119
193
|
country_short = INVALID_IP_ADDRESS
|
@@ -136,6 +210,8 @@ class Ip2location
|
|
136
210
|
mobilebrand = INVALID_IP_ADDRESS
|
137
211
|
elevation = INVALID_IP_ADDRESS
|
138
212
|
usagetype = INVALID_IP_ADDRESS
|
213
|
+
addresstype = INVALID_IP_ADDRESS
|
214
|
+
category = INVALID_IP_ADDRESS
|
139
215
|
end
|
140
216
|
results = {}
|
141
217
|
results['country_short'] = country_short
|
@@ -158,6 +234,8 @@ class Ip2location
|
|
158
234
|
results['mobilebrand'] = mobilebrand
|
159
235
|
results['elevation'] = elevation
|
160
236
|
results['usagetype'] = usagetype
|
237
|
+
results['addresstype'] = addresstype
|
238
|
+
results['category'] = category
|
161
239
|
return results
|
162
240
|
end
|
163
241
|
|
@@ -165,7 +243,9 @@ class Ip2location
|
|
165
243
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
166
244
|
if valid
|
167
245
|
rec = get_record(ip)
|
168
|
-
if
|
246
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
247
|
+
country_short = IPV6_ADDRESS_IN_IPV4_BIN
|
248
|
+
elsif !(rec.nil?)
|
169
249
|
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
170
250
|
else
|
171
251
|
country_short = INVALID_IP_ADDRESS
|
@@ -180,7 +260,9 @@ class Ip2location
|
|
180
260
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
181
261
|
if valid
|
182
262
|
rec = get_record(ip)
|
183
|
-
if
|
263
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
264
|
+
country_long = IPV6_ADDRESS_IN_IPV4_BIN
|
265
|
+
elsif !(rec.nil?)
|
184
266
|
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
185
267
|
else
|
186
268
|
country_long = INVALID_IP_ADDRESS
|
@@ -195,7 +277,9 @@ class Ip2location
|
|
195
277
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
196
278
|
if valid
|
197
279
|
rec = get_record(ip)
|
198
|
-
if
|
280
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
281
|
+
region = IPV6_ADDRESS_IN_IPV4_BIN
|
282
|
+
elsif !(rec.nil?)
|
199
283
|
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
200
284
|
else
|
201
285
|
region = INVALID_IP_ADDRESS
|
@@ -210,7 +294,9 @@ class Ip2location
|
|
210
294
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
211
295
|
if valid
|
212
296
|
rec = get_record(ip)
|
213
|
-
if
|
297
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
298
|
+
city = IPV6_ADDRESS_IN_IPV4_BIN
|
299
|
+
elsif !(rec.nil?)
|
214
300
|
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
215
301
|
else
|
216
302
|
city = INVALID_IP_ADDRESS
|
@@ -225,7 +311,9 @@ class Ip2location
|
|
225
311
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
226
312
|
if valid
|
227
313
|
rec = get_record(ip)
|
228
|
-
if
|
314
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
315
|
+
latitude = IPV6_ADDRESS_IN_IPV4_BIN
|
316
|
+
elsif !(rec.nil?)
|
229
317
|
latitude = (defined?(rec.latitude) && rec.latitude != '') ? rec.latitude : FIELD_NOT_SUPPORTED
|
230
318
|
else
|
231
319
|
latitude = INVALID_IP_ADDRESS
|
@@ -240,7 +328,9 @@ class Ip2location
|
|
240
328
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
241
329
|
if valid
|
242
330
|
rec = get_record(ip)
|
243
|
-
if
|
331
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
332
|
+
longitude = IPV6_ADDRESS_IN_IPV4_BIN
|
333
|
+
elsif !(rec.nil?)
|
244
334
|
longitude = (defined?(rec.longitude) && rec.longitude != '') ? rec.longitude : FIELD_NOT_SUPPORTED
|
245
335
|
else
|
246
336
|
longitude = INVALID_IP_ADDRESS
|
@@ -255,7 +345,9 @@ class Ip2location
|
|
255
345
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
256
346
|
if valid
|
257
347
|
rec = get_record(ip)
|
258
|
-
if
|
348
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
349
|
+
isp = IPV6_ADDRESS_IN_IPV4_BIN
|
350
|
+
elsif !(rec.nil?)
|
259
351
|
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
260
352
|
else
|
261
353
|
isp = INVALID_IP_ADDRESS
|
@@ -270,7 +362,9 @@ class Ip2location
|
|
270
362
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
271
363
|
if valid
|
272
364
|
rec = get_record(ip)
|
273
|
-
if
|
365
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
366
|
+
domain = IPV6_ADDRESS_IN_IPV4_BIN
|
367
|
+
elsif !(rec.nil?)
|
274
368
|
domain = (defined?(rec.domain) && rec.domain != '') ? rec.domain : FIELD_NOT_SUPPORTED
|
275
369
|
else
|
276
370
|
domain = INVALID_IP_ADDRESS
|
@@ -285,7 +379,9 @@ class Ip2location
|
|
285
379
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
286
380
|
if valid
|
287
381
|
rec = get_record(ip)
|
288
|
-
if
|
382
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
383
|
+
zipcode = IPV6_ADDRESS_IN_IPV4_BIN
|
384
|
+
elsif !(rec.nil?)
|
289
385
|
zipcode = (defined?(rec.zipcode) && rec.zipcode != '') ? rec.zipcode : FIELD_NOT_SUPPORTED
|
290
386
|
else
|
291
387
|
zipcode = INVALID_IP_ADDRESS
|
@@ -300,7 +396,9 @@ class Ip2location
|
|
300
396
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
301
397
|
if valid
|
302
398
|
rec = get_record(ip)
|
303
|
-
if
|
399
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
400
|
+
timezone = IPV6_ADDRESS_IN_IPV4_BIN
|
401
|
+
elsif !(rec.nil?)
|
304
402
|
timezone = (defined?(rec.timezone) && rec.timezone != '') ? rec.timezone : FIELD_NOT_SUPPORTED
|
305
403
|
else
|
306
404
|
timezone = INVALID_IP_ADDRESS
|
@@ -315,7 +413,9 @@ class Ip2location
|
|
315
413
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
316
414
|
if valid
|
317
415
|
rec = get_record(ip)
|
318
|
-
if
|
416
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
417
|
+
netspeed = IPV6_ADDRESS_IN_IPV4_BIN
|
418
|
+
elsif !(rec.nil?)
|
319
419
|
netspeed = (defined?(rec.netspeed) && rec.netspeed != '') ? rec.netspeed : FIELD_NOT_SUPPORTED
|
320
420
|
else
|
321
421
|
netspeed = INVALID_IP_ADDRESS
|
@@ -330,7 +430,9 @@ class Ip2location
|
|
330
430
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
331
431
|
if valid
|
332
432
|
rec = get_record(ip)
|
333
|
-
if
|
433
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
434
|
+
iddcode = IPV6_ADDRESS_IN_IPV4_BIN
|
435
|
+
elsif !(rec.nil?)
|
334
436
|
iddcode = (defined?(rec.iddcode) && rec.iddcode != '') ? rec.iddcode : FIELD_NOT_SUPPORTED
|
335
437
|
else
|
336
438
|
iddcode = INVALID_IP_ADDRESS
|
@@ -345,7 +447,9 @@ class Ip2location
|
|
345
447
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
346
448
|
if valid
|
347
449
|
rec = get_record(ip)
|
348
|
-
if
|
450
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
451
|
+
areacode = IPV6_ADDRESS_IN_IPV4_BIN
|
452
|
+
elsif !(rec.nil?)
|
349
453
|
areacode = (defined?(rec.areacode) && rec.areacode != '') ? rec.areacode : FIELD_NOT_SUPPORTED
|
350
454
|
else
|
351
455
|
areacode = INVALID_IP_ADDRESS
|
@@ -360,7 +464,9 @@ class Ip2location
|
|
360
464
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
361
465
|
if valid
|
362
466
|
rec = get_record(ip)
|
363
|
-
if
|
467
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
468
|
+
weatherstationcode = IPV6_ADDRESS_IN_IPV4_BIN
|
469
|
+
elsif !(rec.nil?)
|
364
470
|
weatherstationcode = (defined?(rec.weatherstationcode) && rec.weatherstationcode != '') ? rec.weatherstationcode : FIELD_NOT_SUPPORTED
|
365
471
|
else
|
366
472
|
weatherstationcode = INVALID_IP_ADDRESS
|
@@ -375,7 +481,9 @@ class Ip2location
|
|
375
481
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
376
482
|
if valid
|
377
483
|
rec = get_record(ip)
|
378
|
-
if
|
484
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
485
|
+
weatherstationname = IPV6_ADDRESS_IN_IPV4_BIN
|
486
|
+
elsif !(rec.nil?)
|
379
487
|
weatherstationname = (defined?(rec.weatherstationname) && rec.weatherstationname != '') ? rec.weatherstationname : FIELD_NOT_SUPPORTED
|
380
488
|
else
|
381
489
|
weatherstationname = INVALID_IP_ADDRESS
|
@@ -390,7 +498,9 @@ class Ip2location
|
|
390
498
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
391
499
|
if valid
|
392
500
|
rec = get_record(ip)
|
393
|
-
if
|
501
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
502
|
+
mcc = IPV6_ADDRESS_IN_IPV4_BIN
|
503
|
+
elsif !(rec.nil?)
|
394
504
|
mcc = (defined?(rec.mcc) && rec.mcc != '') ? rec.mcc : FIELD_NOT_SUPPORTED
|
395
505
|
else
|
396
506
|
mcc = INVALID_IP_ADDRESS
|
@@ -405,8 +515,10 @@ class Ip2location
|
|
405
515
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
406
516
|
if valid
|
407
517
|
rec = get_record(ip)
|
408
|
-
if
|
409
|
-
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
|
410
522
|
else
|
411
523
|
mnc = INVALID_IP_ADDRESS
|
412
524
|
end
|
@@ -420,7 +532,9 @@ class Ip2location
|
|
420
532
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
421
533
|
if valid
|
422
534
|
rec = get_record(ip)
|
423
|
-
if
|
535
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
536
|
+
mobilebrand = IPV6_ADDRESS_IN_IPV4_BIN
|
537
|
+
elsif !(rec.nil?)
|
424
538
|
mobilebrand = (defined?(rec.mobilebrand) && rec.mobilebrand != '') ? rec.mobilebrand : FIELD_NOT_SUPPORTED
|
425
539
|
else
|
426
540
|
mobilebrand = INVALID_IP_ADDRESS
|
@@ -435,7 +549,9 @@ class Ip2location
|
|
435
549
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
436
550
|
if valid
|
437
551
|
rec = get_record(ip)
|
438
|
-
if
|
552
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
553
|
+
elevation = IPV6_ADDRESS_IN_IPV4_BIN
|
554
|
+
elsif !(rec.nil?)
|
439
555
|
elevation = (defined?(rec.elevation) && rec.elevation != '') ? rec.elevation : FIELD_NOT_SUPPORTED
|
440
556
|
else
|
441
557
|
elevation = INVALID_IP_ADDRESS
|
@@ -450,7 +566,9 @@ class Ip2location
|
|
450
566
|
valid = !(IPAddr.new(ip) rescue nil).nil?
|
451
567
|
if valid
|
452
568
|
rec = get_record(ip)
|
453
|
-
if
|
569
|
+
if rec == IPV6_ADDRESS_IN_IPV4_BIN
|
570
|
+
usagetype = IPV6_ADDRESS_IN_IPV4_BIN
|
571
|
+
elsif !(rec.nil?)
|
454
572
|
usagetype = (defined?(rec.usagetype) && rec.usagetype != '') ? rec.usagetype : FIELD_NOT_SUPPORTED
|
455
573
|
else
|
456
574
|
usagetype = INVALID_IP_ADDRESS
|
@@ -461,6 +579,40 @@ class Ip2location
|
|
461
579
|
return usagetype
|
462
580
|
end
|
463
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
|
+
|
464
616
|
def bsearch(low, high, ipnum, base_addr, col_length)
|
465
617
|
while low <= high do
|
466
618
|
mid = (low + high) >> 1
|
@@ -535,5 +687,55 @@ class Ip2location
|
|
535
687
|
end
|
536
688
|
|
537
689
|
private :get_record, :bsearch, :get_from_to, :read32, :readipv6
|
690
|
+
end
|
691
|
+
|
692
|
+
class Ip2locationWebService
|
693
|
+
attr_accessor :ws_api_key, :ws_package, :ws_use_ssl
|
694
|
+
|
695
|
+
def initialize(api_key, package, use_ssl)
|
696
|
+
if !api_key.match(/^[0-9A-Z]{10}$/) && api_key != 'demo'
|
697
|
+
raise Exception.new "Please provide a valid IP2Location web service API key."
|
698
|
+
end
|
699
|
+
if !package.match(/^WS[0-9]+$/)
|
700
|
+
package = 'WS1'
|
701
|
+
end
|
702
|
+
if use_ssl == ''
|
703
|
+
use_ssl = true
|
704
|
+
end
|
705
|
+
self.ws_api_key = api_key
|
706
|
+
self.ws_package = package
|
707
|
+
self.ws_use_ssl = use_ssl
|
708
|
+
end
|
538
709
|
|
710
|
+
def lookup(ip, add_ons, language)
|
711
|
+
if self.ws_use_ssl
|
712
|
+
response = Net::HTTP.get(URI("https://api.ip2location.com/v2/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json&addon=" + add_ons + "&lang=" + language))
|
713
|
+
else
|
714
|
+
response = Net::HTTP.get(URI("http://api.ip2location.com/v2/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json&addon=" + add_ons + "&lang=" + language))
|
715
|
+
end
|
716
|
+
parsed_response = JSON.parse(response)
|
717
|
+
if parsed_response.nil?
|
718
|
+
return false
|
719
|
+
end
|
720
|
+
if !parsed_response["response"].nil?
|
721
|
+
raise Exception.new "Error: " + parsed_response["response"]
|
722
|
+
end
|
723
|
+
return parsed_response
|
724
|
+
end
|
725
|
+
|
726
|
+
def get_credit()
|
727
|
+
if self.ws_use_ssl
|
728
|
+
response = Net::HTTP.get(URI("https://api.ip2location.com/v2/?key=" + self.ws_api_key + "&check=true"))
|
729
|
+
else
|
730
|
+
response = Net::HTTP.get(URI("http://api.ip2location.com/v2/?key=" + self.ws_api_key + "&check=true"))
|
731
|
+
end
|
732
|
+
parsed_response = JSON.parse(response)
|
733
|
+
if parsed_response.nil?
|
734
|
+
return 0
|
735
|
+
end
|
736
|
+
if parsed_response["response"].nil?
|
737
|
+
return 0
|
738
|
+
end
|
739
|
+
return parsed_response["response"]
|
740
|
+
end
|
539
741
|
end
|
@@ -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.0
|
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-06-01 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
|
@@ -94,20 +80,6 @@ dependencies:
|
|
94
80
|
- - "~>"
|
95
81
|
- !ruby/object:Gem::Version
|
96
82
|
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
83
|
description: The official IP2Location Ruby library to geolocate an IP address. You
|
112
84
|
can lookup for country, region, city, latitude, longitude, zip code, time zone,
|
113
85
|
ISP, domain, area code, usage type, mobile data, weather data and elevation from
|
@@ -137,10 +109,9 @@ files:
|
|
137
109
|
- lib/ip2location_ruby/ip2location_config.rb
|
138
110
|
- lib/ip2location_ruby/ip2location_record.rb
|
139
111
|
- rb/data/IP2LOCATION-LITE-DB1.IPV6.BIN
|
140
|
-
- spec/assets/
|
141
|
-
- spec/
|
142
|
-
- spec/
|
143
|
-
- spec/ip2location_ruby_spec.rb
|
112
|
+
- spec/assets/IP2LOCATION-LITE-DB1.IPV6.BIN
|
113
|
+
- spec/ip2location_ruby_database_spec.rb
|
114
|
+
- spec/ip2location_ruby_webservice_spec.rb
|
144
115
|
- spec/spec_helper.rb
|
145
116
|
homepage: https://github.com/ip2location/ip2location-ruby
|
146
117
|
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
|