ip2proxy_ruby 1.0.3 → 1.0.4
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/.document +5 -5
- data/.gitignore +9 -9
- data/Gemfile +5 -5
- data/LICENSE.txt +20 -20
- data/README.md +3 -0
- data/Rakefile +2 -2
- data/ip2proxy_ruby.gemspec +74 -67
- data/lib/ip2proxy_ruby.rb +279 -279
- data/lib/ip2proxy_ruby/i2p_database_config.rb +20 -20
- data/lib/ip2proxy_ruby/i2p_ip_data.rb +9 -9
- data/lib/ip2proxy_ruby/i2p_string_data.rb +15 -15
- data/lib/ip2proxy_ruby/ip2proxy_config.rb +16 -16
- data/lib/ip2proxy_ruby/ip2proxy_record.rb +19 -19
- data/spec/ip2proxy_ruby_spec.rb +20 -20
- data/spec/spec_helper.rb +12 -12
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c574300fb7ff35666bf4b8e222a75080e0cd243ed2c44877b8553328b1bc2b9f
|
4
|
+
data.tar.gz: 96090be6428f5d69762a4b27610d93634e757a42592d86a6ab12c01f49b63fbe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 816c038bcf7666b3bc5636b0cedb4e3f23cec2ba5e0b9eaaf2a5f80fc64114e033b4cb5c93538acab8742476168802d51cef867d3fdf96289693a02d8839ac00
|
7
|
+
data.tar.gz: 0d0e6595fcb5972e90458e0bd1ba63376934061784421463354994e218701b9574afa7ffeb2a5c68ab6adfbfed74812bcc64e6cead8e590b16663ecb0586f7d5
|
data/.document
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
lib/**/*.rb
|
2
|
-
bin/*
|
3
|
-
-
|
4
|
-
features/**/*.feature
|
5
|
-
LICENSE.txt
|
1
|
+
lib/**/*.rb
|
2
|
+
bin/*
|
3
|
+
-
|
4
|
+
features/**/*.feature
|
5
|
+
LICENSE.txt
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/Gemfile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in ip2proxy_ruby.gemspec
|
4
|
-
gemspec
|
5
|
-
gem 'bindata'
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in ip2proxy_ruby.gemspec
|
4
|
+
gemspec
|
5
|
+
gem 'bindata'
|
data/LICENSE.txt
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
Copyright (c) 2018 IP2Location ( support@ip2location.com )
|
2
|
-
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
-
a copy of this software and associated documentation files (the
|
5
|
-
"Software"), to deal in the Software without restriction, including
|
6
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
the following conditions:
|
10
|
-
|
11
|
-
The above copyright notice and this permission notice shall be
|
12
|
-
included in all copies or substantial portions of the Software.
|
13
|
-
|
14
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2018 IP2Location ( support@ip2location.com )
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
[](https://rubygems.org/gems/ip2proxy_ruby)
|
2
|
+
[](https://rubygems.org/gems/ip2proxy_ruby)
|
3
|
+
|
1
4
|
# IP2Proxy Ruby Library
|
2
5
|
|
3
6
|
This module allows user to query an IP address if it was being used as open proxy, web proxy, VPN anonymizer and TOR exits. It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
2
|
-
task :default => :spec
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
task :default => :spec
|
data/ip2proxy_ruby.gemspec
CHANGED
@@ -1,67 +1,74 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
|
3
|
-
Gem::Specification.new do |s|
|
4
|
-
s.name = "ip2proxy_ruby"
|
5
|
-
s.version = "1.0.
|
6
|
-
s.authors = ["ip2location"]
|
7
|
-
s.email = ["support@ip2location.com"]
|
8
|
-
|
9
|
-
s.summary = "IP2Proxy Ruby library"
|
10
|
-
s.description = "Ruby library
|
11
|
-
s.homepage = "https://github.com/ip2location/ip2proxy-ruby"
|
12
|
-
s.licenses = ["MIT"]
|
13
|
-
s.require_paths = ["lib"]
|
14
|
-
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE.txt",
|
17
|
-
"README.md"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"Gemfile",
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
28
|
-
"
|
29
|
-
"lib/ip2proxy_ruby.rb",
|
30
|
-
"lib/ip2proxy_ruby/
|
31
|
-
"lib/ip2proxy_ruby/
|
32
|
-
"lib/ip2proxy_ruby/
|
33
|
-
"lib/ip2proxy_ruby/
|
34
|
-
"
|
35
|
-
"spec/
|
36
|
-
"spec/
|
37
|
-
"
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
s.
|
53
|
-
s.
|
54
|
-
s.
|
55
|
-
s.
|
56
|
-
s.
|
57
|
-
s.
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "ip2proxy_ruby"
|
5
|
+
s.version = "1.0.4"
|
6
|
+
s.authors = ["ip2location"]
|
7
|
+
s.email = ["support@ip2location.com"]
|
8
|
+
|
9
|
+
s.summary = "IP2Proxy Ruby library"
|
10
|
+
s.description = "The official IP2Proxy Ruby library to detect anonymous proxy, VPN and Tor exit nodes."
|
11
|
+
s.homepage = "https://github.com/ip2location/ip2proxy-ruby"
|
12
|
+
s.licenses = ["MIT"]
|
13
|
+
s.require_paths = ["lib"]
|
14
|
+
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.md"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".gitignore",
|
22
|
+
"Gemfile",
|
23
|
+
"LICENSE.txt",
|
24
|
+
"README.md",
|
25
|
+
"Rakefile",
|
26
|
+
"ip2proxy_ruby.gemspec",
|
27
|
+
"example.rb",
|
28
|
+
"lib/ip2proxy_ruby.rb",
|
29
|
+
"lib/ip2proxy_ruby/i2p_database_config.rb",
|
30
|
+
"lib/ip2proxy_ruby/i2p_ip_data.rb",
|
31
|
+
"lib/ip2proxy_ruby/i2p_string_data.rb",
|
32
|
+
"lib/ip2proxy_ruby/ip2proxy_config.rb",
|
33
|
+
"lib/ip2proxy_ruby/ip2proxy_record.rb",
|
34
|
+
"spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN",
|
35
|
+
"spec/ip2proxy_ruby_spec.rb",
|
36
|
+
"spec/spec_helper.rb",
|
37
|
+
"rb/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN"
|
38
|
+
]
|
39
|
+
|
40
|
+
if s.respond_to?(:metadata=)
|
41
|
+
s.metadata = {
|
42
|
+
"bug_tracker_uri" => "https://github.com/ip2location/ip2proxy-ruby/issues",
|
43
|
+
"homepage_uri" => "https://www.ip2location.com",
|
44
|
+
"source_code_uri" => "https://github.com/ip2location/ip2proxy-ruby",
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
s.specification_version = 4
|
50
|
+
|
51
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
52
|
+
s.add_runtime_dependency(%q<bindata>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<awesome_print>, [">= 0"])
|
54
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
|
55
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
56
|
+
s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
|
57
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<bindata>, [">= 0"])
|
60
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
62
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
63
|
+
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
64
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
|
+
end
|
66
|
+
else
|
67
|
+
s.add_dependency(%q<bindata>, [">= 0"])
|
68
|
+
s.add_dependency(%q<awesome_print>, [">= 0"])
|
69
|
+
s.add_dependency(%q<rspec>, ["~> 2.8.0"])
|
70
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
71
|
+
s.add_dependency(%q<bundler>, [">= 1.2.0"])
|
72
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
73
|
+
end
|
74
|
+
end
|
data/lib/ip2proxy_ruby.rb
CHANGED
@@ -1,280 +1,280 @@
|
|
1
|
-
require 'bindata'
|
2
|
-
require 'ipaddr'
|
3
|
-
require_relative 'ip2proxy_ruby/ip2proxy_config'
|
4
|
-
require_relative 'ip2proxy_ruby/i2p_database_config'
|
5
|
-
require_relative 'ip2proxy_ruby/i2p_string_data'
|
6
|
-
require_relative 'ip2proxy_ruby/i2p_ip_data'
|
7
|
-
require_relative 'ip2proxy_ruby/ip2proxy_record'
|
8
|
-
|
9
|
-
class Ip2proxy
|
10
|
-
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday
|
11
|
-
|
12
|
-
VERSION = '1.0.
|
13
|
-
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
14
|
-
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
|
15
|
-
|
16
|
-
def open(url)
|
17
|
-
self.file = File.open(File.expand_path url, 'rb')
|
18
|
-
i2p = Ip2proxyConfig.read(file)
|
19
|
-
self.db_index = i2p.databasetype
|
20
|
-
self.columns = i2p.databasecolumn + 0
|
21
|
-
self.databaseyear = 2000 + i2p.databaseyear
|
22
|
-
self.databasemonth = i2p.databasemonth
|
23
|
-
self.databaseday = i2p.databaseday
|
24
|
-
self.database = I2pDbConfig.setup_database(self.db_index)
|
25
|
-
self.ipv4databasecount = i2p.ipv4databasecount
|
26
|
-
self.ipv4databaseaddr = i2p.ipv4databaseaddr
|
27
|
-
self.ipv6databasecount = i2p.ipv6databasecount
|
28
|
-
self.ipv6databaseaddr = i2p.ipv6databaseaddr
|
29
|
-
self.ipv4indexbaseaddr = i2p.ipv4indexbaseaddr
|
30
|
-
self.ipv6indexbaseaddr = i2p.ipv6indexbaseaddr
|
31
|
-
self.record_class4 = (Ip2ProxyRecord.init database, 4)
|
32
|
-
self.record_class6 = (Ip2ProxyRecord.init database, 6)
|
33
|
-
self
|
34
|
-
end
|
35
|
-
|
36
|
-
def close()
|
37
|
-
self.file.close
|
38
|
-
end
|
39
|
-
|
40
|
-
def get_module_version()
|
41
|
-
return VERSION
|
42
|
-
end
|
43
|
-
|
44
|
-
def get_package_version()
|
45
|
-
return (self.db_index).to_s
|
46
|
-
end
|
47
|
-
|
48
|
-
def get_database_version()
|
49
|
-
return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s
|
50
|
-
end
|
51
|
-
|
52
|
-
def get_record(ip)
|
53
|
-
ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
|
54
|
-
self.ip_version = ipno.ipv4? ? 4 : 6
|
55
|
-
self.v4 = ipno.ipv4?
|
56
|
-
self.count = ipno.ipv4? ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
57
|
-
self.base_addr = (ipno.ipv4? ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
|
58
|
-
|
59
|
-
ipnum = ipno.to_i + 0
|
60
|
-
col_length = columns * 4
|
61
|
-
|
62
|
-
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
63
|
-
indexpos = 0
|
64
|
-
case ip_version
|
65
|
-
when 4
|
66
|
-
ipnum1_2 = (ipnum >> 16)
|
67
|
-
indexpos = ipv4indexbaseaddr + (ipnum1_2 << 3)
|
68
|
-
when 6
|
69
|
-
ipnum1 = (ipnum / (2**112))
|
70
|
-
indexpos = ipv6indexbaseaddr + (ipnum1 << 3)
|
71
|
-
end
|
72
|
-
low = read32(indexpos)
|
73
|
-
high = read32(indexpos + 4)
|
74
|
-
return self.record = bsearch(low, high, ipnum, self.base_addr, col_length)
|
75
|
-
else
|
76
|
-
return self.record = bsearch(0, self.count, ipnum, self.base_addr, col_length)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
def get_country_short(ip)
|
81
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
82
|
-
if valid
|
83
|
-
rec = get_record(ip)
|
84
|
-
if !(rec.nil?)
|
85
|
-
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
86
|
-
else
|
87
|
-
country_short = INVALID_IP_ADDRESS
|
88
|
-
end
|
89
|
-
else
|
90
|
-
country_short = INVALID_IP_ADDRESS
|
91
|
-
end
|
92
|
-
return country_short
|
93
|
-
end
|
94
|
-
|
95
|
-
def get_country_long(ip)
|
96
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
97
|
-
if valid
|
98
|
-
rec = get_record(ip)
|
99
|
-
if !(rec.nil?)
|
100
|
-
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
101
|
-
else
|
102
|
-
country_long = INVALID_IP_ADDRESS
|
103
|
-
end
|
104
|
-
else
|
105
|
-
country_long = INVALID_IP_ADDRESS
|
106
|
-
end
|
107
|
-
return country_long
|
108
|
-
end
|
109
|
-
|
110
|
-
def get_region(ip)
|
111
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
112
|
-
if valid
|
113
|
-
rec = get_record(ip)
|
114
|
-
if !(rec.nil?)
|
115
|
-
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
116
|
-
else
|
117
|
-
region = INVALID_IP_ADDRESS
|
118
|
-
end
|
119
|
-
else
|
120
|
-
region = INVALID_IP_ADDRESS
|
121
|
-
end
|
122
|
-
return region
|
123
|
-
end
|
124
|
-
|
125
|
-
def get_city(ip)
|
126
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
127
|
-
if valid
|
128
|
-
rec = get_record(ip)
|
129
|
-
if !(rec.nil?)
|
130
|
-
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
131
|
-
else
|
132
|
-
city = INVALID_IP_ADDRESS
|
133
|
-
end
|
134
|
-
else
|
135
|
-
city = INVALID_IP_ADDRESS
|
136
|
-
end
|
137
|
-
return city
|
138
|
-
end
|
139
|
-
|
140
|
-
def get_isp(ip)
|
141
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
142
|
-
if valid
|
143
|
-
rec = get_record(ip)
|
144
|
-
if !(rec.nil?)
|
145
|
-
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
146
|
-
else
|
147
|
-
isp = INVALID_IP_ADDRESS
|
148
|
-
end
|
149
|
-
else
|
150
|
-
isp = INVALID_IP_ADDRESS
|
151
|
-
end
|
152
|
-
return isp
|
153
|
-
end
|
154
|
-
|
155
|
-
def get_proxytype(ip)
|
156
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
157
|
-
if valid
|
158
|
-
rec = get_record(ip)
|
159
|
-
if !(rec.nil?)
|
160
|
-
proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED
|
161
|
-
else
|
162
|
-
proxytype = INVALID_IP_ADDRESS
|
163
|
-
end
|
164
|
-
else
|
165
|
-
proxytype = INVALID_IP_ADDRESS
|
166
|
-
end
|
167
|
-
return proxytype
|
168
|
-
end
|
169
|
-
|
170
|
-
def is_proxy(ip)
|
171
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
172
|
-
if valid
|
173
|
-
rec = get_record(ip)
|
174
|
-
if !(rec.nil?)
|
175
|
-
if self.db_index == 1
|
176
|
-
isproxy = (rec.country_short == '-') ? 0 : 1
|
177
|
-
else
|
178
|
-
isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1
|
179
|
-
end
|
180
|
-
else
|
181
|
-
isproxy = -1
|
182
|
-
end
|
183
|
-
else
|
184
|
-
isproxy = -1
|
185
|
-
end
|
186
|
-
return isproxy
|
187
|
-
end
|
188
|
-
|
189
|
-
def get_all(ip)
|
190
|
-
valid = !(IPAddr.new(ip) rescue nil).nil?
|
191
|
-
if valid
|
192
|
-
rec = get_record(ip)
|
193
|
-
if !(rec.nil?)
|
194
|
-
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
195
|
-
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
196
|
-
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
197
|
-
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
198
|
-
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
199
|
-
proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED
|
200
|
-
|
201
|
-
if self.db_index == 1
|
202
|
-
isproxy = (rec.country_short == '-') ? 0 : 1
|
203
|
-
else
|
204
|
-
isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1
|
205
|
-
end
|
206
|
-
else
|
207
|
-
country_short = INVALID_IP_ADDRESS
|
208
|
-
country_long = INVALID_IP_ADDRESS
|
209
|
-
region = INVALID_IP_ADDRESS
|
210
|
-
city = INVALID_IP_ADDRESS
|
211
|
-
isp = INVALID_IP_ADDRESS
|
212
|
-
proxytype = INVALID_IP_ADDRESS
|
213
|
-
isproxy = -1
|
214
|
-
end
|
215
|
-
else
|
216
|
-
country_short = INVALID_IP_ADDRESS
|
217
|
-
country_long = INVALID_IP_ADDRESS
|
218
|
-
region = INVALID_IP_ADDRESS
|
219
|
-
city = INVALID_IP_ADDRESS
|
220
|
-
isp = INVALID_IP_ADDRESS
|
221
|
-
proxytype = INVALID_IP_ADDRESS
|
222
|
-
isproxy = -1
|
223
|
-
end
|
224
|
-
|
225
|
-
results = {}
|
226
|
-
results['is_proxy'] = isproxy
|
227
|
-
results['proxy_type'] = proxytype
|
228
|
-
results['country_short'] = country_short
|
229
|
-
results['country_long'] = country_long
|
230
|
-
results['region'] = region
|
231
|
-
results['city'] = city
|
232
|
-
results['isp'] = isp
|
233
|
-
|
234
|
-
return results
|
235
|
-
end
|
236
|
-
|
237
|
-
def bsearch(low, high, ipnum, base_addr, col_length)
|
238
|
-
while low <= high do
|
239
|
-
mid = (low + high) >> 1
|
240
|
-
ip_from, ip_to = get_from_to(mid, base_addr, col_length)
|
241
|
-
if ipnum >= ip_from && ipnum < ip_to
|
242
|
-
from_base = ( base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
|
243
|
-
file.seek(from_base)
|
244
|
-
if v4
|
245
|
-
return self.record_class4.read(file)
|
246
|
-
else
|
247
|
-
return self.record_class6.read(file)
|
248
|
-
end
|
249
|
-
else
|
250
|
-
if ipnum < ip_from
|
251
|
-
high = mid - 1
|
252
|
-
else
|
253
|
-
low = mid + 1
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
258
|
-
|
259
|
-
def get_from_to(mid, base_addr, col_length)
|
260
|
-
from_base = ( base_addr + mid * (col_length + (v4 ? 0 : 12)))
|
261
|
-
file.seek(from_base)
|
262
|
-
ip_from = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
263
|
-
file.seek(from_base + col_length + (v4 ? 0 : 12))
|
264
|
-
ip_to = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
265
|
-
[ip_from, ip_to]
|
266
|
-
end
|
267
|
-
|
268
|
-
def read32(indexp)
|
269
|
-
file.seek(indexp - 1)
|
270
|
-
return file.read(4).unpack('V').first
|
271
|
-
end
|
272
|
-
|
273
|
-
def readipv6(filer)
|
274
|
-
parts = filer.read(16).unpack('V*')
|
275
|
-
return parts[0] + parts[1] * 4294967296 + parts[2] * 4294967296**2 + parts[3] * 4294967296**3
|
276
|
-
end
|
277
|
-
|
278
|
-
private :get_record, :bsearch, :get_from_to, :read32, :readipv6
|
279
|
-
|
1
|
+
require 'bindata'
|
2
|
+
require 'ipaddr'
|
3
|
+
require_relative 'ip2proxy_ruby/ip2proxy_config'
|
4
|
+
require_relative 'ip2proxy_ruby/i2p_database_config'
|
5
|
+
require_relative 'ip2proxy_ruby/i2p_string_data'
|
6
|
+
require_relative 'ip2proxy_ruby/i2p_ip_data'
|
7
|
+
require_relative 'ip2proxy_ruby/ip2proxy_record'
|
8
|
+
|
9
|
+
class Ip2proxy
|
10
|
+
attr_accessor :record_class4, :record_class6, :v4, :file, :db_index, :count, :base_addr, :ipno, :record, :database, :columns, :ip_version, :ipv4databasecount, :ipv4databaseaddr, :ipv4indexbaseaddr, :ipv6databasecount, :ipv6databaseaddr, :ipv6indexbaseaddr, :databaseyear, :databasemonth, :databaseday
|
11
|
+
|
12
|
+
VERSION = '1.0.4'
|
13
|
+
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
14
|
+
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
|
15
|
+
|
16
|
+
def open(url)
|
17
|
+
self.file = File.open(File.expand_path url, 'rb')
|
18
|
+
i2p = Ip2proxyConfig.read(file)
|
19
|
+
self.db_index = i2p.databasetype
|
20
|
+
self.columns = i2p.databasecolumn + 0
|
21
|
+
self.databaseyear = 2000 + i2p.databaseyear
|
22
|
+
self.databasemonth = i2p.databasemonth
|
23
|
+
self.databaseday = i2p.databaseday
|
24
|
+
self.database = I2pDbConfig.setup_database(self.db_index)
|
25
|
+
self.ipv4databasecount = i2p.ipv4databasecount
|
26
|
+
self.ipv4databaseaddr = i2p.ipv4databaseaddr
|
27
|
+
self.ipv6databasecount = i2p.ipv6databasecount
|
28
|
+
self.ipv6databaseaddr = i2p.ipv6databaseaddr
|
29
|
+
self.ipv4indexbaseaddr = i2p.ipv4indexbaseaddr
|
30
|
+
self.ipv6indexbaseaddr = i2p.ipv6indexbaseaddr
|
31
|
+
self.record_class4 = (Ip2ProxyRecord.init database, 4)
|
32
|
+
self.record_class6 = (Ip2ProxyRecord.init database, 6)
|
33
|
+
self
|
34
|
+
end
|
35
|
+
|
36
|
+
def close()
|
37
|
+
self.file.close
|
38
|
+
end
|
39
|
+
|
40
|
+
def get_module_version()
|
41
|
+
return VERSION
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_package_version()
|
45
|
+
return (self.db_index).to_s
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_database_version()
|
49
|
+
return (self.databaseyear).to_s + "." + (self.databasemonth).to_s + "." + (self.databaseday).to_s
|
50
|
+
end
|
51
|
+
|
52
|
+
def get_record(ip)
|
53
|
+
ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
|
54
|
+
self.ip_version = ipno.ipv4? ? 4 : 6
|
55
|
+
self.v4 = ipno.ipv4?
|
56
|
+
self.count = ipno.ipv4? ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
57
|
+
self.base_addr = (ipno.ipv4? ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
|
58
|
+
|
59
|
+
ipnum = ipno.to_i + 0
|
60
|
+
col_length = columns * 4
|
61
|
+
|
62
|
+
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
63
|
+
indexpos = 0
|
64
|
+
case ip_version
|
65
|
+
when 4
|
66
|
+
ipnum1_2 = (ipnum >> 16)
|
67
|
+
indexpos = ipv4indexbaseaddr + (ipnum1_2 << 3)
|
68
|
+
when 6
|
69
|
+
ipnum1 = (ipnum / (2**112))
|
70
|
+
indexpos = ipv6indexbaseaddr + (ipnum1 << 3)
|
71
|
+
end
|
72
|
+
low = read32(indexpos)
|
73
|
+
high = read32(indexpos + 4)
|
74
|
+
return self.record = bsearch(low, high, ipnum, self.base_addr, col_length)
|
75
|
+
else
|
76
|
+
return self.record = bsearch(0, self.count, ipnum, self.base_addr, col_length)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def get_country_short(ip)
|
81
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
82
|
+
if valid
|
83
|
+
rec = get_record(ip)
|
84
|
+
if !(rec.nil?)
|
85
|
+
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
86
|
+
else
|
87
|
+
country_short = INVALID_IP_ADDRESS
|
88
|
+
end
|
89
|
+
else
|
90
|
+
country_short = INVALID_IP_ADDRESS
|
91
|
+
end
|
92
|
+
return country_short
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_country_long(ip)
|
96
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
97
|
+
if valid
|
98
|
+
rec = get_record(ip)
|
99
|
+
if !(rec.nil?)
|
100
|
+
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
101
|
+
else
|
102
|
+
country_long = INVALID_IP_ADDRESS
|
103
|
+
end
|
104
|
+
else
|
105
|
+
country_long = INVALID_IP_ADDRESS
|
106
|
+
end
|
107
|
+
return country_long
|
108
|
+
end
|
109
|
+
|
110
|
+
def get_region(ip)
|
111
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
112
|
+
if valid
|
113
|
+
rec = get_record(ip)
|
114
|
+
if !(rec.nil?)
|
115
|
+
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
116
|
+
else
|
117
|
+
region = INVALID_IP_ADDRESS
|
118
|
+
end
|
119
|
+
else
|
120
|
+
region = INVALID_IP_ADDRESS
|
121
|
+
end
|
122
|
+
return region
|
123
|
+
end
|
124
|
+
|
125
|
+
def get_city(ip)
|
126
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
127
|
+
if valid
|
128
|
+
rec = get_record(ip)
|
129
|
+
if !(rec.nil?)
|
130
|
+
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
131
|
+
else
|
132
|
+
city = INVALID_IP_ADDRESS
|
133
|
+
end
|
134
|
+
else
|
135
|
+
city = INVALID_IP_ADDRESS
|
136
|
+
end
|
137
|
+
return city
|
138
|
+
end
|
139
|
+
|
140
|
+
def get_isp(ip)
|
141
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
142
|
+
if valid
|
143
|
+
rec = get_record(ip)
|
144
|
+
if !(rec.nil?)
|
145
|
+
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
146
|
+
else
|
147
|
+
isp = INVALID_IP_ADDRESS
|
148
|
+
end
|
149
|
+
else
|
150
|
+
isp = INVALID_IP_ADDRESS
|
151
|
+
end
|
152
|
+
return isp
|
153
|
+
end
|
154
|
+
|
155
|
+
def get_proxytype(ip)
|
156
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
157
|
+
if valid
|
158
|
+
rec = get_record(ip)
|
159
|
+
if !(rec.nil?)
|
160
|
+
proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED
|
161
|
+
else
|
162
|
+
proxytype = INVALID_IP_ADDRESS
|
163
|
+
end
|
164
|
+
else
|
165
|
+
proxytype = INVALID_IP_ADDRESS
|
166
|
+
end
|
167
|
+
return proxytype
|
168
|
+
end
|
169
|
+
|
170
|
+
def is_proxy(ip)
|
171
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
172
|
+
if valid
|
173
|
+
rec = get_record(ip)
|
174
|
+
if !(rec.nil?)
|
175
|
+
if self.db_index == 1
|
176
|
+
isproxy = (rec.country_short == '-') ? 0 : 1
|
177
|
+
else
|
178
|
+
isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1
|
179
|
+
end
|
180
|
+
else
|
181
|
+
isproxy = -1
|
182
|
+
end
|
183
|
+
else
|
184
|
+
isproxy = -1
|
185
|
+
end
|
186
|
+
return isproxy
|
187
|
+
end
|
188
|
+
|
189
|
+
def get_all(ip)
|
190
|
+
valid = !(IPAddr.new(ip) rescue nil).nil?
|
191
|
+
if valid
|
192
|
+
rec = get_record(ip)
|
193
|
+
if !(rec.nil?)
|
194
|
+
country_short = (defined?(rec.country_short) && rec.country_short != '') ? rec.country_short : FIELD_NOT_SUPPORTED
|
195
|
+
country_long = (defined?(rec.country_long) && rec.country_long != '') ? rec.country_long : FIELD_NOT_SUPPORTED
|
196
|
+
region = (defined?(rec.region) && rec.region != '') ? rec.region : FIELD_NOT_SUPPORTED
|
197
|
+
city = (defined?(rec.city) && rec.city != '') ? rec.city : FIELD_NOT_SUPPORTED
|
198
|
+
isp = (defined?(rec.isp) && rec.isp != '') ? rec.isp : FIELD_NOT_SUPPORTED
|
199
|
+
proxytype = (defined?(rec.proxytype) && rec.proxytype != '') ? rec.proxytype : FIELD_NOT_SUPPORTED
|
200
|
+
|
201
|
+
if self.db_index == 1
|
202
|
+
isproxy = (rec.country_short == '-') ? 0 : 1
|
203
|
+
else
|
204
|
+
isproxy = (rec.proxytype == '-') ? 0 : (rec.proxytype == 'DCH') ? 2 : 1
|
205
|
+
end
|
206
|
+
else
|
207
|
+
country_short = INVALID_IP_ADDRESS
|
208
|
+
country_long = INVALID_IP_ADDRESS
|
209
|
+
region = INVALID_IP_ADDRESS
|
210
|
+
city = INVALID_IP_ADDRESS
|
211
|
+
isp = INVALID_IP_ADDRESS
|
212
|
+
proxytype = INVALID_IP_ADDRESS
|
213
|
+
isproxy = -1
|
214
|
+
end
|
215
|
+
else
|
216
|
+
country_short = INVALID_IP_ADDRESS
|
217
|
+
country_long = INVALID_IP_ADDRESS
|
218
|
+
region = INVALID_IP_ADDRESS
|
219
|
+
city = INVALID_IP_ADDRESS
|
220
|
+
isp = INVALID_IP_ADDRESS
|
221
|
+
proxytype = INVALID_IP_ADDRESS
|
222
|
+
isproxy = -1
|
223
|
+
end
|
224
|
+
|
225
|
+
results = {}
|
226
|
+
results['is_proxy'] = isproxy
|
227
|
+
results['proxy_type'] = proxytype
|
228
|
+
results['country_short'] = country_short
|
229
|
+
results['country_long'] = country_long
|
230
|
+
results['region'] = region
|
231
|
+
results['city'] = city
|
232
|
+
results['isp'] = isp
|
233
|
+
|
234
|
+
return results
|
235
|
+
end
|
236
|
+
|
237
|
+
def bsearch(low, high, ipnum, base_addr, col_length)
|
238
|
+
while low <= high do
|
239
|
+
mid = (low + high) >> 1
|
240
|
+
ip_from, ip_to = get_from_to(mid, base_addr, col_length)
|
241
|
+
if ipnum >= ip_from && ipnum < ip_to
|
242
|
+
from_base = ( base_addr + mid * (col_length + (self.v4 ? 0 : 12)))
|
243
|
+
file.seek(from_base)
|
244
|
+
if v4
|
245
|
+
return self.record_class4.read(file)
|
246
|
+
else
|
247
|
+
return self.record_class6.read(file)
|
248
|
+
end
|
249
|
+
else
|
250
|
+
if ipnum < ip_from
|
251
|
+
high = mid - 1
|
252
|
+
else
|
253
|
+
low = mid + 1
|
254
|
+
end
|
255
|
+
end
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def get_from_to(mid, base_addr, col_length)
|
260
|
+
from_base = ( base_addr + mid * (col_length + (v4 ? 0 : 12)))
|
261
|
+
file.seek(from_base)
|
262
|
+
ip_from = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
263
|
+
file.seek(from_base + col_length + (v4 ? 0 : 12))
|
264
|
+
ip_to = v4 ? file.read(4).unpack('V').first : readipv6(file)
|
265
|
+
[ip_from, ip_to]
|
266
|
+
end
|
267
|
+
|
268
|
+
def read32(indexp)
|
269
|
+
file.seek(indexp - 1)
|
270
|
+
return file.read(4).unpack('V').first
|
271
|
+
end
|
272
|
+
|
273
|
+
def readipv6(filer)
|
274
|
+
parts = filer.read(16).unpack('V*')
|
275
|
+
return parts[0] + parts[1] * 4294967296 + parts[2] * 4294967296**2 + parts[3] * 4294967296**3
|
276
|
+
end
|
277
|
+
|
278
|
+
private :get_record, :bsearch, :get_from_to, :read32, :readipv6
|
279
|
+
|
280
280
|
end
|
@@ -1,21 +1,21 @@
|
|
1
|
-
class I2pDbConfig
|
2
|
-
COLUMNS = {
|
3
|
-
:COUNTRY => [0, 2, 3, 3, 3],
|
4
|
-
:REGION => [0, 0, 0, 4, 4],
|
5
|
-
:CITY => [0, 0, 0, 5, 5],
|
6
|
-
:ISP => [0, 0, 0, 0, 6],
|
7
|
-
:PROXYTYPE => [0, 0, 2, 2, 2]
|
8
|
-
}
|
9
|
-
|
10
|
-
def self.setup_database(db_index)
|
11
|
-
# strip all 0 value & downcase keys
|
12
|
-
cols = COLUMNS.inject({}) {|memo, (key, value)|
|
13
|
-
(memo[key.to_s.downcase.to_sym] = value[db_index] if value[db_index] > 0)
|
14
|
-
memo
|
15
|
-
}
|
16
|
-
# order by value
|
17
|
-
col_array = cols.sort_by {|key,value| value}
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
1
|
+
class I2pDbConfig
|
2
|
+
COLUMNS = {
|
3
|
+
:COUNTRY => [0, 2, 3, 3, 3],
|
4
|
+
:REGION => [0, 0, 0, 4, 4],
|
5
|
+
:CITY => [0, 0, 0, 5, 5],
|
6
|
+
:ISP => [0, 0, 0, 0, 6],
|
7
|
+
:PROXYTYPE => [0, 0, 2, 2, 2]
|
8
|
+
}
|
9
|
+
|
10
|
+
def self.setup_database(db_index)
|
11
|
+
# strip all 0 value & downcase keys
|
12
|
+
cols = COLUMNS.inject({}) {|memo, (key, value)|
|
13
|
+
(memo[key.to_s.downcase.to_sym] = value[db_index] if value[db_index] > 0)
|
14
|
+
memo
|
15
|
+
}
|
16
|
+
# order by value
|
17
|
+
col_array = cols.sort_by {|key,value| value}
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
21
|
|
@@ -1,10 +1,10 @@
|
|
1
|
-
class I2pIpData < BinData::BasePrimitive
|
2
|
-
def read_and_return_value(io)
|
3
|
-
iv = eval_parameter(:ip_version)
|
4
|
-
if iv == 4
|
5
|
-
addr = BinData::Uint32le.read(io)
|
6
|
-
elsif iv == 6
|
7
|
-
addr = BinData::Uint128le.read(io)
|
8
|
-
end
|
9
|
-
end
|
1
|
+
class I2pIpData < BinData::BasePrimitive
|
2
|
+
def read_and_return_value(io)
|
3
|
+
iv = eval_parameter(:ip_version)
|
4
|
+
if iv == 4
|
5
|
+
addr = BinData::Uint32le.read(io)
|
6
|
+
elsif iv == 6
|
7
|
+
addr = BinData::Uint128le.read(io)
|
8
|
+
end
|
9
|
+
end
|
10
10
|
end
|
@@ -1,16 +1,16 @@
|
|
1
|
-
class I2pStringData < BinData::BasePrimitive
|
2
|
-
|
3
|
-
def read_and_return_value(io)
|
4
|
-
country_long = eval_parameter(:country_long)
|
5
|
-
io.seekbytes(-4) if country_long
|
6
|
-
file = io.instance_variable_get('@raw_io')
|
7
|
-
addr = BinData::Uint32le.read(io)
|
8
|
-
old_offset = file.tell
|
9
|
-
country_long ? file.seek(addr + 3) : file.seek(addr)
|
10
|
-
length = BinData::Uint8.read(file)
|
11
|
-
res = BinData::String.new(:length => length).read(file)
|
12
|
-
file.seek(old_offset)
|
13
|
-
res
|
14
|
-
end
|
15
|
-
|
1
|
+
class I2pStringData < BinData::BasePrimitive
|
2
|
+
|
3
|
+
def read_and_return_value(io)
|
4
|
+
country_long = eval_parameter(:country_long)
|
5
|
+
io.seekbytes(-4) if country_long
|
6
|
+
file = io.instance_variable_get('@raw_io')
|
7
|
+
addr = BinData::Uint32le.read(io)
|
8
|
+
old_offset = file.tell
|
9
|
+
country_long ? file.seek(addr + 3) : file.seek(addr)
|
10
|
+
length = BinData::Uint8.read(file)
|
11
|
+
res = BinData::String.new(:length => length).read(file)
|
12
|
+
file.seek(old_offset)
|
13
|
+
res
|
14
|
+
end
|
15
|
+
|
16
16
|
end
|
@@ -1,17 +1,17 @@
|
|
1
|
-
class Ip2proxyConfig < BinData::Record
|
2
|
-
endian :little
|
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
|
-
uint32 :ipv4databasecount
|
12
|
-
uint32 :ipv4databaseaddr
|
13
|
-
uint32 :ipv6databasecount
|
14
|
-
uint32 :ipv6databaseaddr
|
15
|
-
uint32 :ipv4indexbaseaddr
|
16
|
-
uint32 :ipv6indexbaseaddr
|
1
|
+
class Ip2proxyConfig < BinData::Record
|
2
|
+
endian :little
|
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
|
+
uint32 :ipv4databasecount
|
12
|
+
uint32 :ipv4databaseaddr
|
13
|
+
uint32 :ipv6databasecount
|
14
|
+
uint32 :ipv6databaseaddr
|
15
|
+
uint32 :ipv4indexbaseaddr
|
16
|
+
uint32 :ipv6indexbaseaddr
|
17
17
|
end
|
@@ -1,20 +1,20 @@
|
|
1
|
-
class Ip2ProxyRecord
|
2
|
-
def self.init(database, ip_version)
|
3
|
-
cls = Class.new(BinData::Record)
|
4
|
-
cls.class_eval {
|
5
|
-
endian :little
|
6
|
-
i2p_ip_data :ip_from, :ip_version => ip_version
|
7
|
-
database.each do |col|
|
8
|
-
if col.first == :country
|
9
|
-
i2p_string_data :country_short
|
10
|
-
i2p_string_data :country_long, :country_long => true
|
11
|
-
else
|
12
|
-
i2p_string_data col.first
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
i2p_ip_data :ip_to, :ip_version => ip_version
|
17
|
-
}
|
18
|
-
cls
|
19
|
-
end
|
1
|
+
class Ip2ProxyRecord
|
2
|
+
def self.init(database, ip_version)
|
3
|
+
cls = Class.new(BinData::Record)
|
4
|
+
cls.class_eval {
|
5
|
+
endian :little
|
6
|
+
i2p_ip_data :ip_from, :ip_version => ip_version
|
7
|
+
database.each do |col|
|
8
|
+
if col.first == :country
|
9
|
+
i2p_string_data :country_short
|
10
|
+
i2p_string_data :country_long, :country_long => true
|
11
|
+
else
|
12
|
+
i2p_string_data col.first
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
i2p_ip_data :ip_to, :ip_version => ip_version
|
17
|
+
}
|
18
|
+
cls
|
19
|
+
end
|
20
20
|
end
|
data/spec/ip2proxy_ruby_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
-
|
3
|
-
describe "Ip2proxy" do
|
4
|
-
it "work correctly with ipv4" do
|
5
|
-
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")
|
6
|
-
record = i2p.get_all('1.0.241.135')
|
7
|
-
record.should_not be_nil
|
8
|
-
record['is_proxy'].should == 1
|
9
|
-
i2p.close()
|
10
|
-
end
|
11
|
-
|
12
|
-
it "work correctly with ipv6" do
|
13
|
-
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")
|
14
|
-
record = i2p.get_all('2001::')
|
15
|
-
record.should_not be_nil
|
16
|
-
record['is_proxy'].should == 0
|
17
|
-
i2p.close()
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ip2proxy" do
|
4
|
+
it "work correctly with ipv4" do
|
5
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")
|
6
|
+
record = i2p.get_all('1.0.241.135')
|
7
|
+
record.should_not be_nil
|
8
|
+
record['is_proxy'].should == 1
|
9
|
+
i2p.close()
|
10
|
+
end
|
11
|
+
|
12
|
+
it "work correctly with ipv6" do
|
13
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN")
|
14
|
+
record = i2p.get_all('2001::')
|
15
|
+
record.should_not be_nil
|
16
|
+
record['is_proxy'].should == 0
|
17
|
+
i2p.close()
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
-
require 'rspec'
|
4
|
-
require 'ip2proxy_ruby'
|
5
|
-
|
6
|
-
# Requires supporting files with custom matchers and macros, etc,
|
7
|
-
# in ./support/ and its subdirectories.
|
8
|
-
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
-
|
10
|
-
RSpec.configure do |config|
|
11
|
-
|
12
|
-
end
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'ip2proxy_ruby'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
13
13
|
require 'awesome_print'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ip2proxy_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
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: 2019-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -94,7 +94,8 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
|
-
description: Ruby library
|
97
|
+
description: The official IP2Proxy Ruby library to detect anonymous proxy, VPN and
|
98
|
+
Tor exit nodes.
|
98
99
|
email:
|
99
100
|
- support@ip2location.com
|
100
101
|
executables: []
|
@@ -106,7 +107,6 @@ files:
|
|
106
107
|
- ".document"
|
107
108
|
- ".gitignore"
|
108
109
|
- Gemfile
|
109
|
-
- Gemfile.lock
|
110
110
|
- LICENSE.txt
|
111
111
|
- README.md
|
112
112
|
- Rakefile
|
@@ -125,7 +125,10 @@ files:
|
|
125
125
|
homepage: https://github.com/ip2location/ip2proxy-ruby
|
126
126
|
licenses:
|
127
127
|
- MIT
|
128
|
-
metadata:
|
128
|
+
metadata:
|
129
|
+
bug_tracker_uri: https://github.com/ip2location/ip2proxy-ruby/issues
|
130
|
+
homepage_uri: https://www.ip2location.com
|
131
|
+
source_code_uri: https://github.com/ip2location/ip2proxy-ruby
|
129
132
|
post_install_message:
|
130
133
|
rdoc_options: []
|
131
134
|
require_paths:
|