ip2location_ruby 7.0.0 → 8.0.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/README.rdoc +15 -4
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/ip2location_ruby.gemspec +6 -6
- data/lib/ip2location_ruby/ip2location_config.rb +2 -0
- data/lib/ip2location_ruby.rb +156 -30
- 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
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6498bb18d849412de400120c7e71a6f1f4fe7bfa
|
4
|
+
data.tar.gz: fc922eede3355f2223b152d491194f654c9a56fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4730d2e28e3b5815ccb9949ca64d7d7918e3228b1ce2942f9d46313c1020527cc6a3042a0c8410fc750360627bb5467116aac6efdbd8351103ebbe670f60983a
|
7
|
+
data.tar.gz: 9bc77be32a4edf9480a8e13cdc40d5802747e1bc448a837a398db956229c0a1de638b28a666dea75c523302c787f4d87bfe5a3a0f0a102f5f4dadb3492ecc302
|
data/README.rdoc
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
=
|
1
|
+
= IP2Location Ruby Library
|
2
|
+
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, and usage type by IP address or hostname originates from. The library reads the geo location information
|
3
|
+
from **IP2Location BIN data** file.
|
4
|
+
|
5
|
+
Supported IPv4 and IPv6 address.
|
6
|
+
|
7
|
+
For more details, please visit:
|
8
|
+
[http://www.ip2location.com/developers/ruby](http://www.ip2location.com/developers/ruby)
|
2
9
|
|
3
10
|
== Usage
|
4
11
|
|
@@ -17,8 +24,12 @@
|
|
17
24
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
18
25
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
19
26
|
|
20
|
-
==
|
27
|
+
== Sample BIN Databases
|
28
|
+
|
29
|
+
* Download free IP2Location LITE databases at [http://lite.ip2location.com](http://lite.ip2location.com)
|
30
|
+
* Download IP2Location sample databases at [http://www.ip2location.com/developers](http://www.ip2location.com/developers)
|
21
31
|
|
22
|
-
|
23
|
-
further details.
|
32
|
+
== Support
|
24
33
|
|
34
|
+
Email: support@ip2location.com
|
35
|
+
URL: [http://www.ip2location.com](http://www.ip2location.com)
|
data/Rakefile
CHANGED
@@ -15,11 +15,11 @@ require 'jeweler'
|
|
15
15
|
Jeweler::Tasks.new do |gem|
|
16
16
|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
17
|
gem.name = "ip2location_ruby"
|
18
|
-
gem.homepage = "
|
18
|
+
gem.homepage = "https://github.com/ip2location/ip2location-ruby"
|
19
19
|
gem.license = "MIT"
|
20
20
|
gem.summary = %Q{the ip2location ruby library}
|
21
|
-
gem.description = %Q{
|
22
|
-
gem.email = "
|
21
|
+
gem.description = %Q{ip2location ruby library}
|
22
|
+
gem.email = "support@ip2location.com"
|
23
23
|
gem.authors = ["Vincent.Z"]
|
24
24
|
# dependencies defined in Gemfile
|
25
25
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
8.0.1
|
data/ip2location_ruby.gemspec
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: ip2location_ruby
|
5
|
+
# stub: ip2location_ruby 8.0.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "ip2location_ruby"
|
9
|
-
s.version = "
|
9
|
+
s.version = "8.0.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Vincent.Z"]
|
14
|
-
s.date = "
|
15
|
-
s.description = "
|
16
|
-
s.email = "
|
14
|
+
s.date = "2016-07-25"
|
15
|
+
s.description = "ip2location ruby library"
|
16
|
+
s.email = "support@ip2location.com"
|
17
17
|
s.extra_rdoc_files = [
|
18
18
|
"LICENSE.txt",
|
19
19
|
"README.rdoc"
|
@@ -41,7 +41,7 @@ Gem::Specification.new do |s|
|
|
41
41
|
"spec/ip2location_ruby_spec.rb",
|
42
42
|
"spec/spec_helper.rb"
|
43
43
|
]
|
44
|
-
s.homepage = "
|
44
|
+
s.homepage = "https://github.com/ip2location/ip2location-ruby"
|
45
45
|
s.licenses = ["MIT"]
|
46
46
|
s.rubygems_version = "2.4.1"
|
47
47
|
s.summary = "the ip2location ruby library"
|
data/lib/ip2location_ruby.rb
CHANGED
@@ -9,7 +9,7 @@ require 'ip2location_ruby/i2l_ip_data'
|
|
9
9
|
require 'ip2location_ruby/ip2location_record'
|
10
10
|
|
11
11
|
class Ip2location
|
12
|
-
attr_accessor :
|
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
|
13
13
|
|
14
14
|
def open(url)
|
15
15
|
self.file = File.open(File.expand_path url, 'rb')
|
@@ -21,6 +21,10 @@ class Ip2location
|
|
21
21
|
self.ipv4databaseaddr = i2l.ipv4databaseaddr
|
22
22
|
self.ipv6databasecount = i2l.ipv6databasecount
|
23
23
|
self.ipv6databaseaddr = i2l.ipv6databaseaddr
|
24
|
+
self.ipv4indexbaseaddr = i2l.ipv4indexbaseaddr
|
25
|
+
self.ipv6indexbaseaddr = i2l.ipv6indexbaseaddr
|
26
|
+
self.record_class4 = (Ip2LocationRecord.init database, 4)
|
27
|
+
self.record_class6 = (Ip2LocationRecord.init database, 6)
|
24
28
|
self
|
25
29
|
end
|
26
30
|
|
@@ -30,45 +34,167 @@ class Ip2location
|
|
30
34
|
self.v4 = ipno.ipv4?
|
31
35
|
self.count = ipno.ipv4? ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
32
36
|
self.base_addr = (ipno.ipv4? ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
|
33
|
-
|
34
|
-
|
37
|
+
|
35
38
|
ipnum = ipno.to_i + 0
|
36
39
|
col_length = columns * 4
|
37
|
-
|
38
|
-
|
40
|
+
|
41
|
+
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
42
|
+
indexpos = 0
|
43
|
+
case ip_version
|
44
|
+
when 4
|
45
|
+
ipnum1_2 = (ipnum >> 16)
|
46
|
+
indexpos = ipv4indexbaseaddr + (ipnum1_2 << 3)
|
47
|
+
when 6
|
48
|
+
ipnum1 = (ipnum / (2**112))
|
49
|
+
indexpos = ipv6indexbaseaddr + (ipnum1 << 3)
|
50
|
+
end
|
51
|
+
low = read32(indexpos)
|
52
|
+
high = read32(indexpos + 4)
|
53
|
+
return self.record = bsearch(low, high, ipnum, self.base_addr, col_length)
|
54
|
+
else
|
55
|
+
return self.record = bsearch(0, self.count, ipnum, self.base_addr, col_length)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_country_short(ip)
|
60
|
+
rec = get_all(ip)
|
61
|
+
return rec.country_short
|
62
|
+
end
|
63
|
+
|
64
|
+
def get_country_long(ip)
|
65
|
+
rec = get_all(ip)
|
66
|
+
return rec.country_long
|
67
|
+
end
|
68
|
+
|
69
|
+
def get_region(ip)
|
70
|
+
rec = get_all(ip)
|
71
|
+
return rec.region
|
72
|
+
end
|
73
|
+
|
74
|
+
def get_city(ip)
|
75
|
+
rec = get_all(ip)
|
76
|
+
return rec.city
|
77
|
+
end
|
78
|
+
|
79
|
+
def get_latitude(ip)
|
80
|
+
rec = get_all(ip)
|
81
|
+
return rec.latitude
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_longitude(ip)
|
85
|
+
rec = get_all(ip)
|
86
|
+
return rec.longitude
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_isp(ip)
|
90
|
+
rec = get_all(ip)
|
91
|
+
return rec.isp
|
92
|
+
end
|
93
|
+
|
94
|
+
def get_domain(ip)
|
95
|
+
rec = get_all(ip)
|
96
|
+
return rec.domain
|
97
|
+
end
|
98
|
+
|
99
|
+
def get_zipcode(ip)
|
100
|
+
rec = get_all(ip)
|
101
|
+
return rec.zipcode
|
102
|
+
end
|
103
|
+
|
104
|
+
def get_timezone(ip)
|
105
|
+
rec = get_all(ip)
|
106
|
+
return rec.timezone
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_netspeed(ip)
|
110
|
+
rec = get_all(ip)
|
111
|
+
return rec.netspeed
|
112
|
+
end
|
113
|
+
|
114
|
+
def get_iddcode(ip)
|
115
|
+
rec = get_all(ip)
|
116
|
+
return rec.iddcode
|
117
|
+
end
|
118
|
+
|
119
|
+
def get_areacode(ip)
|
120
|
+
rec = get_all(ip)
|
121
|
+
return rec.areacode
|
122
|
+
end
|
123
|
+
|
124
|
+
def get_weatherstationcode(ip)
|
125
|
+
rec = get_all(ip)
|
126
|
+
return rec.weatherstationcode
|
127
|
+
end
|
128
|
+
|
129
|
+
def get_weatherstationname(ip)
|
130
|
+
rec = get_all(ip)
|
131
|
+
return rec.weatherstationname
|
132
|
+
end
|
133
|
+
|
134
|
+
def get_mcc(ip)
|
135
|
+
rec = get_all(ip)
|
136
|
+
return rec.mcc
|
137
|
+
end
|
138
|
+
|
139
|
+
def get_mnc(ip)
|
140
|
+
rec = get_all(ip)
|
141
|
+
return rec.mnc
|
142
|
+
end
|
143
|
+
|
144
|
+
def get_mobilebrand(ip)
|
145
|
+
rec = get_all(ip)
|
146
|
+
return rec.mobilebrand
|
147
|
+
end
|
148
|
+
|
149
|
+
def get_elevation(ip)
|
150
|
+
rec = get_all(ip)
|
151
|
+
return rec.elevation
|
152
|
+
end
|
153
|
+
|
154
|
+
def get_usagetype(ip)
|
155
|
+
rec = get_all(ip)
|
156
|
+
return rec.usagetype
|
157
|
+
end
|
158
|
+
|
159
|
+
def bsearch(low, high, ipnum, base_addr, col_length)
|
160
|
+
while low <= high do
|
161
|
+
mid = (low + high) >> 1
|
162
|
+
ip_from, ip_to = get_from_to(mid, base_addr, col_length)
|
163
|
+
if ipnum >= ip_from && ipnum < ip_to
|
164
|
+
from_base = ( base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
|
165
|
+
file.seek(from_base)
|
166
|
+
if v4
|
167
|
+
return self.record_class4.read(file)
|
168
|
+
else
|
169
|
+
return self.record_class6.read(file)
|
170
|
+
end
|
171
|
+
else
|
172
|
+
if ipnum < ip_from
|
173
|
+
high = mid - 1
|
174
|
+
else
|
175
|
+
low = mid + 1
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
39
179
|
end
|
40
180
|
|
41
181
|
def get_from_to(mid, base_addr, col_length)
|
42
182
|
from_base = ( base_addr + mid * (col_length + (v4 ? 0 : 12)))
|
43
183
|
file.seek(from_base)
|
44
|
-
|
184
|
+
ip_from = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
45
185
|
file.seek(from_base + col_length + (v4 ? 0 : 12))
|
46
|
-
|
186
|
+
ip_to = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
47
187
|
[ip_from, ip_to]
|
48
188
|
end
|
49
189
|
|
50
|
-
def
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
elsif ipnum >= ip_to
|
59
|
-
low = mid
|
60
|
-
high = high
|
61
|
-
return bsearch(low, high, ipnum, base_addr, col_length)
|
62
|
-
else
|
63
|
-
from_base = ( base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
|
64
|
-
file.seek(from_base)
|
65
|
-
return self.record_class.read(file)
|
66
|
-
end
|
190
|
+
def read32(indexp)
|
191
|
+
file.seek(indexp - 1)
|
192
|
+
return file.read(4).unpack('V').first
|
193
|
+
end
|
194
|
+
|
195
|
+
def readipv6(filer)
|
196
|
+
parts = filer.read(16).unpack('V*')
|
197
|
+
return parts[0] + parts[1] * 4294967296 + parts[2] * 4294967296**2 + parts[3] * 4294967296**3
|
67
198
|
end
|
68
199
|
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
200
|
+
end
|
data/spec/assets/DB24.DEMO4.BIN
CHANGED
File without changes
|
data/spec/assets/DB24.DEMO6.BIN
CHANGED
File without changes
|
File without changes
|
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:
|
4
|
+
version: 8.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vincent.Z
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-07-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -108,8 +108,8 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
-
description:
|
112
|
-
email:
|
111
|
+
description: ip2location ruby library
|
112
|
+
email: support@ip2location.com
|
113
113
|
executables: []
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files:
|
@@ -137,7 +137,7 @@ files:
|
|
137
137
|
- spec/assets/IP-COUNTRY-SAMPLE.BIN
|
138
138
|
- spec/ip2location_ruby_spec.rb
|
139
139
|
- spec/spec_helper.rb
|
140
|
-
homepage:
|
140
|
+
homepage: https://github.com/ip2location/ip2location-ruby
|
141
141
|
licenses:
|
142
142
|
- MIT
|
143
143
|
metadata: {}
|
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
157
157
|
version: '0'
|
158
158
|
requirements: []
|
159
159
|
rubyforge_project:
|
160
|
-
rubygems_version: 2.
|
160
|
+
rubygems_version: 2.5.1
|
161
161
|
signing_key:
|
162
162
|
specification_version: 4
|
163
163
|
summary: the ip2location ruby library
|