ip2proxy_ruby 2.1.0 → 3.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE.txt +20 -20
- data/README.md +98 -119
- data/example.rb +52 -41
- data/ip2proxy_ruby.gemspec +5 -11
- data/lib/ip2proxy_ruby.rb +524 -408
- data/lib/ip2proxy_ruby/i2p_database_config.rb +27 -25
- 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 +19 -16
- data/lib/ip2proxy_ruby/ip2proxy_record.rb +19 -19
- data/rb/data/PX11.SAMPLE.BIN +0 -0
- data/spec/assets/PX11.SAMPLE.BIN +0 -0
- data/spec/ip2proxy_ruby_database_spec.rb +123 -0
- data/spec/spec_helper.rb +0 -1
- metadata +11 -37
- data/rb/data/IP2PROXY-LITE-PX1.BIN +0 -0
- data/spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN +0 -0
- data/spec/ip2proxy_ruby_spec.rb +0 -20
@@ -1,26 +1,28 @@
|
|
1
|
-
class I2pDbConfig
|
2
|
-
COLUMNS = {
|
3
|
-
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3],
|
4
|
-
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4],
|
5
|
-
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5],
|
6
|
-
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6],
|
7
|
-
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2],
|
8
|
-
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7],
|
9
|
-
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8],
|
10
|
-
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9],
|
11
|
-
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10],
|
12
|
-
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
1
|
+
class I2pDbConfig
|
2
|
+
COLUMNS = {
|
3
|
+
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3],
|
4
|
+
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 4],
|
5
|
+
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5],
|
6
|
+
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6, 6],
|
7
|
+
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2],
|
8
|
+
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7],
|
9
|
+
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8, 8],
|
10
|
+
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9, 9],
|
11
|
+
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10, 10],
|
12
|
+
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11, 11],
|
13
|
+
:THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12, 12],
|
14
|
+
:PROVIDER => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 13]
|
15
|
+
}
|
16
|
+
|
17
|
+
def self.setup_database(db_index)
|
18
|
+
# strip all 0 value & downcase keys
|
19
|
+
cols = COLUMNS.inject({}) {|memo, (key, value)|
|
20
|
+
(memo[key.to_s.downcase.to_sym] = value[db_index] if value[db_index] > 0)
|
21
|
+
memo
|
22
|
+
}
|
23
|
+
# order by value
|
24
|
+
col_array = cols.sort_by {|key,value| value}
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
26
28
|
|
@@ -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,20 @@
|
|
1
|
-
class Ip2proxyConfig < BinData::Record
|
2
|
-
endian :little
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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
|
+
uint8 :productcode
|
18
|
+
uint8 :licensecode
|
19
|
+
uint32 :databasesize
|
17
20
|
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
|
Binary file
|
Binary file
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "Ip2proxy" do
|
4
|
+
it "work correctly with invalid ip" do
|
5
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
6
|
+
record = i2p.get_all('1.0.0.x')
|
7
|
+
expect(record['country_short']).to eq 'INVALID IP ADDRESS'
|
8
|
+
end
|
9
|
+
|
10
|
+
it "work correctly with get_all ipv4" do
|
11
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
12
|
+
record = i2p.get_all('1.0.0.8')
|
13
|
+
expect(record['country_short']).to eq 'US'
|
14
|
+
end
|
15
|
+
|
16
|
+
it "work correctly with get_country_short" do
|
17
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
18
|
+
record = i2p.get_country_short('1.0.0.8')
|
19
|
+
expect(record).to eq 'US'
|
20
|
+
end
|
21
|
+
|
22
|
+
it "work correctly with get_country_long" do
|
23
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
24
|
+
record = i2p.get_country_long('1.0.0.8')
|
25
|
+
expect(record).to eq 'United States of America'
|
26
|
+
end
|
27
|
+
|
28
|
+
it "work correctly with get_region" do
|
29
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
30
|
+
record = i2p.get_region('1.0.0.8')
|
31
|
+
expect(record).to eq 'California'
|
32
|
+
end
|
33
|
+
|
34
|
+
it "work correctly with get_city" do
|
35
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
36
|
+
record = i2p.get_city('1.0.0.8')
|
37
|
+
expect(record).to eq 'Los Angeles'
|
38
|
+
end
|
39
|
+
|
40
|
+
it "work correctly with get_isp" do
|
41
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
42
|
+
record = i2p.get_isp('1.0.0.8')
|
43
|
+
expect(record).to eq 'APNIC and CloudFlare DNS Resolver Project'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "work correctly with get_domain" do
|
47
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
48
|
+
record = i2p.get_domain('1.0.0.8')
|
49
|
+
expect(record).to eq 'cloudflare.com'
|
50
|
+
end
|
51
|
+
|
52
|
+
it "work correctly with get_usagetype" do
|
53
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
54
|
+
record = i2p.get_usagetype('1.0.0.8')
|
55
|
+
expect(record).to eq 'CDN'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "work correctly with get_asn" do
|
59
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
60
|
+
record = i2p.get_asn('1.0.0.8')
|
61
|
+
expect(record).to eq '13335'
|
62
|
+
end
|
63
|
+
|
64
|
+
it "work correctly with get_as" do
|
65
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
66
|
+
record = i2p.get_as('1.0.0.8')
|
67
|
+
expect(record).to eq 'CLOUDFLARENET'
|
68
|
+
end
|
69
|
+
|
70
|
+
it "work correctly with get_last_seen" do
|
71
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
72
|
+
record = i2p.get_last_seen('1.0.0.8')
|
73
|
+
expect(record).to eq '22'
|
74
|
+
end
|
75
|
+
|
76
|
+
it "work correctly with get_threat" do
|
77
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
78
|
+
record = i2p.get_threat('1.0.0.8')
|
79
|
+
expect(record).to eq '-'
|
80
|
+
end
|
81
|
+
|
82
|
+
it "work correctly with is_proxy" do
|
83
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
84
|
+
record = i2p.is_proxy('1.0.0.8')
|
85
|
+
expect(record).to eq 2
|
86
|
+
end
|
87
|
+
|
88
|
+
it "work correctly with get_proxytype" do
|
89
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
90
|
+
record = i2p.get_proxytype('1.0.0.8')
|
91
|
+
expect(record).to eq 'DCH'
|
92
|
+
end
|
93
|
+
|
94
|
+
it "work correctly with get_provider" do
|
95
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
96
|
+
record = i2p.get_provider('1.0.0.8')
|
97
|
+
expect(record).to eq 'CloudFlare'
|
98
|
+
end
|
99
|
+
|
100
|
+
it "work correctly with get_all ipv6" do
|
101
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
102
|
+
record = i2p.get_all('2c0f:ffa0::4')
|
103
|
+
expect(record['country_short']).to eq 'UG'
|
104
|
+
end
|
105
|
+
|
106
|
+
it "work correctly with get_module_version" do
|
107
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
108
|
+
record = i2p.get_module_version()
|
109
|
+
expect(record).to eq '3.2.0'
|
110
|
+
end
|
111
|
+
|
112
|
+
it "work correctly with get_package_version" do
|
113
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
114
|
+
record = i2p.get_package_version()
|
115
|
+
expect(record).to eq '11'
|
116
|
+
end
|
117
|
+
|
118
|
+
it "work correctly with get_database_version" do
|
119
|
+
i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
|
120
|
+
record = i2p.get_database_version()
|
121
|
+
expect(record).to eq '2021.5.28'
|
122
|
+
end
|
123
|
+
end
|
data/spec/spec_helper.rb
CHANGED
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: 2.
|
4
|
+
version: 3.2.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-08-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: awesome_print
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rspec
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,24 +66,11 @@ dependencies:
|
|
80
66
|
- - ">="
|
81
67
|
- !ruby/object:Gem::Version
|
82
68
|
version: 1.2.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: simplecov
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
97
69
|
description: The official IP2Proxy Ruby library to detect VPN servers, open proxies,
|
98
|
-
web proxies, Tor exit nodes, search engine robots
|
99
|
-
BIN database. Other information available includes proxy
|
100
|
-
ISP, domain name, usage type, AS number, AS name
|
70
|
+
web proxies, Tor exit nodes, search engine robots, data center ranges and residential
|
71
|
+
proxies using IP2Proxy BIN database. Other information available includes proxy
|
72
|
+
type, country, state, city, ISP, domain name, usage type, AS number, AS name, threats,
|
73
|
+
last seen date and provider names.
|
101
74
|
email:
|
102
75
|
- support@ip2location.com
|
103
76
|
executables: []
|
@@ -120,9 +93,9 @@ files:
|
|
120
93
|
- lib/ip2proxy_ruby/i2p_string_data.rb
|
121
94
|
- lib/ip2proxy_ruby/ip2proxy_config.rb
|
122
95
|
- lib/ip2proxy_ruby/ip2proxy_record.rb
|
123
|
-
- rb/data/
|
124
|
-
- spec/assets/
|
125
|
-
- spec/
|
96
|
+
- rb/data/PX11.SAMPLE.BIN
|
97
|
+
- spec/assets/PX11.SAMPLE.BIN
|
98
|
+
- spec/ip2proxy_ruby_database_spec.rb
|
126
99
|
- spec/spec_helper.rb
|
127
100
|
homepage: https://github.com/ip2location/ip2proxy-ruby
|
128
101
|
licenses:
|
@@ -146,7 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
119
|
- !ruby/object:Gem::Version
|
147
120
|
version: '0'
|
148
121
|
requirements: []
|
149
|
-
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 2.7.6.2
|
150
124
|
signing_key:
|
151
125
|
specification_version: 4
|
152
126
|
summary: IP2Proxy Ruby library
|
Binary file
|
Binary file
|
data/spec/ip2proxy_ruby_spec.rb
DELETED
@@ -1,20 +0,0 @@
|
|
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
|