ip2proxy_ruby 2.0.0 → 2.1.0
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/example.rb +1 -1
- data/ip2proxy_ruby.gemspec +2 -2
- data/lib/ip2proxy_ruby.rb +50 -16
- data/rb/data/IP2PROXY-LITE-PX1.BIN +0 -0
- metadata +4 -5
- data/rb/data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1dc20326c582b22c3ada59ab4987c530b54a4c1693546783fe03ac0afa4d7c3d
|
4
|
+
data.tar.gz: e40ee8fc6baec6675fbe8375646d78a3e7d38f0b37f5fb7d8840fbc6b78a7026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 947b66ffec9139e7531e9569c9da945b056c842304ab4d866b918995cfb20834d439197d7c7b1119c6a2611fbe2c4fff60ea69126960ef916f1c1e6ea1eb05ce
|
7
|
+
data.tar.gz: e182e739e69e2160610b911e67d51997b4a41f58f851d526ea3742b1ddc692aa31cd10790984fad532d0bc92750d7096d2f7aa6201af361e6f7678a39e8e64be
|
data/example.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'ip2proxy_ruby'
|
2
2
|
|
3
3
|
# open IP2Proxy BIN database for proxy lookup
|
4
|
-
i2p = Ip2proxy.new.open("./data/IP2PROXY-
|
4
|
+
i2p = Ip2proxy.new.open("./data/IP2PROXY-LITE-PX1.BIN")
|
5
5
|
|
6
6
|
# get versioning information
|
7
7
|
print 'Module Version: ' + i2p.get_module_version + "\n"
|
data/ip2proxy_ruby.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = "ip2proxy_ruby"
|
5
|
-
s.version = "2.
|
5
|
+
s.version = "2.1.0"
|
6
6
|
s.authors = ["ip2location"]
|
7
7
|
s.email = ["support@ip2location.com"]
|
8
8
|
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |s|
|
|
34
34
|
"spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN",
|
35
35
|
"spec/ip2proxy_ruby_spec.rb",
|
36
36
|
"spec/spec_helper.rb",
|
37
|
-
"rb/data/IP2PROXY-
|
37
|
+
"rb/data/IP2PROXY-LITE-PX1.BIN"
|
38
38
|
]
|
39
39
|
|
40
40
|
if s.respond_to?(:metadata=)
|
data/lib/ip2proxy_ruby.rb
CHANGED
@@ -9,7 +9,7 @@ require_relative 'ip2proxy_ruby/ip2proxy_record'
|
|
9
9
|
class Ip2proxy
|
10
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
11
|
|
12
|
-
VERSION = '2.
|
12
|
+
VERSION = '2.1.0'
|
13
13
|
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
|
14
14
|
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
|
15
15
|
|
@@ -51,23 +51,28 @@ class Ip2proxy
|
|
51
51
|
|
52
52
|
def get_record(ip)
|
53
53
|
ipno = IPAddr.new(ip, Socket::AF_UNSPEC)
|
54
|
-
self.ip_version = ipno
|
55
|
-
self.v4 =
|
56
|
-
self.count =
|
57
|
-
self.base_addr = (
|
58
|
-
|
59
|
-
ipnum = ipno.to_i + 0
|
54
|
+
self.ip_version, ipnum = validateip(ipno)
|
55
|
+
self.v4 = ip_version == 4 ? true : false
|
56
|
+
self.count = v4 ? self.ipv4databasecount + 0 : self.ipv6databasecount + 0
|
57
|
+
self.base_addr = (v4 ? self.ipv4databaseaddr - 1 : self.ipv6databaseaddr - 1)
|
60
58
|
col_length = columns * 4
|
61
|
-
|
62
59
|
if ipv4indexbaseaddr > 0 || ipv6indexbaseaddr > 0
|
63
60
|
indexpos = 0
|
64
61
|
case ip_version
|
65
62
|
when 4
|
66
|
-
|
67
|
-
|
63
|
+
indexpos = ipv4indexbaseaddr + ((ipnum >> 16) << 3)
|
64
|
+
realipno = ipnum
|
65
|
+
# if ipnum reach MAX_IPV4_RANGE
|
66
|
+
if realipno == 4294967295
|
67
|
+
ipnum = realipno - 1
|
68
|
+
end
|
68
69
|
when 6
|
69
|
-
|
70
|
-
|
70
|
+
indexpos = ipv6indexbaseaddr + ((ipnum >> 112) << 3)
|
71
|
+
realipno = ipnum
|
72
|
+
# if ipnum reach MAX_IPV6_RANGE
|
73
|
+
if realipno == 340282366920938463463374607431768211455
|
74
|
+
ipnum = realipno - 1
|
75
|
+
end
|
71
76
|
end
|
72
77
|
low = read32(indexpos)
|
73
78
|
high = read32(indexpos + 4)
|
@@ -277,7 +282,6 @@ class Ip2proxy
|
|
277
282
|
asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
|
278
283
|
as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
|
279
284
|
last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
|
280
|
-
|
281
285
|
if self.db_index == 1
|
282
286
|
isproxy = (rec.country_short == '-') ? 0 : 1
|
283
287
|
else
|
@@ -311,7 +315,6 @@ class Ip2proxy
|
|
311
315
|
last_seen = INVALID_IP_ADDRESS
|
312
316
|
isproxy = -1
|
313
317
|
end
|
314
|
-
|
315
318
|
results = {}
|
316
319
|
results['is_proxy'] = isproxy
|
317
320
|
results['proxy_type'] = proxytype
|
@@ -325,7 +328,6 @@ class Ip2proxy
|
|
325
328
|
results['asn'] = asn
|
326
329
|
results['as'] = as
|
327
330
|
results['last_seen'] = last_seen
|
328
|
-
|
329
331
|
return results
|
330
332
|
end
|
331
333
|
|
@@ -348,7 +350,7 @@ class Ip2proxy
|
|
348
350
|
low = mid + 1
|
349
351
|
end
|
350
352
|
end
|
351
|
-
end
|
353
|
+
end
|
352
354
|
end
|
353
355
|
|
354
356
|
def get_from_to(mid, base_addr, col_length)
|
@@ -360,6 +362,38 @@ class Ip2proxy
|
|
360
362
|
[ip_from, ip_to]
|
361
363
|
end
|
362
364
|
|
365
|
+
def validateip(ip)
|
366
|
+
if ip.ipv4?
|
367
|
+
ipv = 4
|
368
|
+
ipnum = ip.to_i + 0
|
369
|
+
else
|
370
|
+
ipv = 6
|
371
|
+
ipnum = ip.to_i + 0
|
372
|
+
#reformat ipv4 address in ipv6
|
373
|
+
if ipnum >= 281470681743360 && ipnum <= 281474976710655
|
374
|
+
ipv = 4
|
375
|
+
ipnum = ipnum - 281470681743360
|
376
|
+
end
|
377
|
+
#reformat 6to4 address to ipv4 address 2002:: to 2002:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF
|
378
|
+
if ipnum >= 42545680458834377588178886921629466624 && ipnum <= 42550872755692912415807417417958686719
|
379
|
+
ipv = 4
|
380
|
+
#bitshift right 80 bits
|
381
|
+
ipnum = ipnum >> 80
|
382
|
+
#bitwise modulus to get the last 32 bit
|
383
|
+
ipnum = ipnum % 4294967296
|
384
|
+
end
|
385
|
+
#reformat Teredo address to ipv4 address 2001:0000:: to 2001:0000:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:
|
386
|
+
if ipnum >= 42540488161975842760550356425300246528 && ipnum <= 42540488241204005274814694018844196863
|
387
|
+
ipv = 4
|
388
|
+
#bitwise not to invert binary
|
389
|
+
ipnum = ~ipnum
|
390
|
+
#bitwise modulus to get the last 32 bit
|
391
|
+
ipnum = ipnum % 4294967296
|
392
|
+
end
|
393
|
+
end
|
394
|
+
[ipv, ipnum]
|
395
|
+
end
|
396
|
+
|
363
397
|
def read32(indexp)
|
364
398
|
file.seek(indexp - 1)
|
365
399
|
return file.read(4).unpack('V').first
|
Binary file
|
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: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ip2location
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05
|
11
|
+
date: 2019-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -120,7 +120,7 @@ files:
|
|
120
120
|
- lib/ip2proxy_ruby/i2p_string_data.rb
|
121
121
|
- lib/ip2proxy_ruby/ip2proxy_config.rb
|
122
122
|
- lib/ip2proxy_ruby/ip2proxy_record.rb
|
123
|
-
- rb/data/IP2PROXY-
|
123
|
+
- rb/data/IP2PROXY-LITE-PX1.BIN
|
124
124
|
- spec/assets/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP.SAMPLE.BIN
|
125
125
|
- spec/ip2proxy_ruby_spec.rb
|
126
126
|
- spec/spec_helper.rb
|
@@ -146,8 +146,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
requirements: []
|
149
|
-
|
150
|
-
rubygems_version: 2.7.6.2
|
149
|
+
rubygems_version: 3.0.3
|
151
150
|
signing_key:
|
152
151
|
specification_version: 4
|
153
152
|
summary: IP2Proxy Ruby library
|
Binary file
|