Skip to content

Commit 9df6cdf

Browse files
committed
Added supports for threats (PX9) & residential proxies (PX10).
1 parent 7f27228 commit 9df6cdf

File tree

5 files changed

+58
-24
lines changed

5 files changed

+58
-24
lines changed

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
# IP2Proxy Ruby Library
55

6-
This module allows user to reverse search of IP address to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots and data center ranges using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name and last seen date.
6+
This module allows user to reverse search of IP address to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots, data center ranges and residential proxies using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name, threats and last seen date.
77

88
It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
99

@@ -22,12 +22,12 @@ Below are the methods supported in this module.
2222
|---|---|
2323
|open|Open the IP2Proxy BIN data with **File I/O** mode for lookup.|
2424
|close|Close and clean up the file pointer.|
25-
|get_package_version|Get the package version (1 to 8 for PX1 to PX8 respectively).|
25+
|get_package_version|Get the package version (1 to 10 for PX1 to PX10 respectively).|
2626
|get_module_version|Get the module version.|
2727
|get_database_version|Get the database version.|
2828
|is_proxy|Check whether if an IP address was a proxy. Please see [Proxy Type](#proxy-type) for details. Returned value:<ul><li>-1 : errors</li><li>0 : not a proxy</li><li>1 : a proxy</li><li>2 : a data center IP address</li></ul>|
2929
|get_all|Return the proxy information in array.|
30-
|get_proxytype|Return the proxy type. Please visit <a href="https://www.ip2location.com/databases/px8-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen" target="_blank">IP2Location</a> for the list of proxy types supported|
30+
|get_proxytype|Return the proxy type. Please visit <a href="https://www.ip2location.com/database/px10-ip-proxytype-country-region-city-isp-domain-usagetype-asn-lastseen-threat-residential" target="_blank">IP2Location</a> for the list of proxy types supported|
3131
|get_country_short|Return the ISO3166-1 country code (2-digits) of the proxy.|
3232
|get_country_long|Return the ISO3166-1 country name of the proxy.|
3333
|get_region|Return the ISO3166-2 region name of the proxy. Please visit <a href="https://www.ip2location.com/free/iso3166-2" target="_blank">ISO3166-2 Subdivision Code</a> for the information of ISO3166-2 supported|
@@ -38,14 +38,15 @@ Below are the methods supported in this module.
3838
|get_asn|Return the autonomous system number (ASN) of proxy's IP address or domain name.|
3939
|get_as|Return the autonomous system (AS) name of proxy's IP address or domain name.|
4040
|get_last_seen|Return the last seen days ago value of proxy's IP address or domain name.|
41+
|get_threat|Return the threat types reported to proxy's IP address or domain name. Please see [Threat Type](#threat-type) for details.|
4142

4243
## Usage
4344

4445
```
4546
require 'ip2proxy_ruby'
4647
4748
# open IP2Proxy BIN database for proxy lookup
48-
i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN")
49+
i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN")
4950
5051
# get versioning information
5152
print 'Module Version: ' + i2p.get_module_version + "\n"
@@ -65,6 +66,7 @@ print 'Usage Type: ' + i2p.get_usagetype('1.2.3.4') + "\n"
6566
print 'ASN: ' + i2p.get_asn('1.2.3.4') + "\n"
6667
print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
6768
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
69+
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
6870
6971
# single function to get all proxy data returned in array
7072
record = i2p.get_all('1.2.3.4')
@@ -80,6 +82,7 @@ print 'Usage Type: ' + record['usagetype'] + "\n"
8082
print 'ASN: ' + record['asn'] + "\n"
8183
print 'AS: ' + record['as'] + "\n"
8284
print 'Last Seen: ' + record['last_seen'] + "\n"
85+
print 'Threat: ' + record['threat'] + "\n"
8386
8487
# close IP2Proxy BIN database
8588
i2p.close()
@@ -89,12 +92,13 @@ i2p.close()
8992

9093
|Proxy Type|Description|
9194
|---|---|
92-
|VPN|Anonymizing VPN services.|
93-
|TOR|Tor Exit Nodes.|
94-
|PUB|Public Proxies.|
95-
|WEB|Web Proxies.|
96-
|DCH|Hosting Providers/Data Center.|
97-
|SES|Search Engine Robots.
95+
|VPN|Anonymizing VPN services|
96+
|TOR|Tor Exit Nodes|
97+
|PUB|Public Proxies|
98+
|WEB|Web Proxies|
99+
|DCH|Hosting Providers/Data Center|
100+
|SES|Search Engine Robots|
101+
|RES|Residential Proxies [PX10+]|
98102

99103
### Usage Type
100104

@@ -113,7 +117,15 @@ i2p.close()
113117
|SES|Search Engine Spider|
114118
|RSV|Reserved|
115119

120+
### Threat Type
121+
122+
|Threat Type|Description|
123+
|---|---|
124+
|SPAM|Spammer|
125+
|SCANNER|Security Scanner or Attack|
126+
|BOTNET|Spyware or Malware|
127+
116128
## Support
117129

118-
130+
119131
URL: [https://www.ip2location.com](https://www.ip2location.com)

example.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
print 'ASN: ' + i2p.get_asn('1.2.3.4') + "\n"
2222
print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
2323
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
24+
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
2425

2526
# single function to get all proxy data returned in array
2627
record = i2p.get_all('1.2.3.4')
@@ -36,6 +37,7 @@
3637
print 'ASN: ' + record['asn'] + "\n"
3738
print 'AS: ' + record['as'] + "\n"
3839
print 'Last Seen: ' + record['last_seen'] + "\n"
40+
print 'Threat: ' + record['threat'] + "\n"
3941

4042
# close IP2Proxy BIN database
4143
i2p.close()

ip2proxy_ruby.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
Gem::Specification.new do |s|
44
s.name = "ip2proxy_ruby"
5-
s.version = "2.1.0"
5+
s.version = "3.0.0"
66
s.authors = ["ip2location"]
77
s.email = ["[email protected]"]
88

99
s.summary = "IP2Proxy Ruby library"
10-
s.description = "The official IP2Proxy Ruby library to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots and data center ranges using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name and last seen date."
10+
s.description = "The official IP2Proxy Ruby library to detect VPN servers, open proxies, web proxies, Tor exit nodes, search engine robots, data center ranges and residential proxies using IP2Proxy BIN database. Other information available includes proxy type, country, state, city, ISP, domain name, usage type, AS number, AS name, threats and last seen date."
1111
s.homepage = "https://github.com/ip2location/ip2proxy-ruby"
1212
s.licenses = ["MIT"]
1313
s.require_paths = ["lib"]

lib/ip2proxy_ruby.rb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class Ip2proxy
1010
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
1111

12-
VERSION = '2.1.0'
12+
VERSION = '3.0.0'
1313
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
1414
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
1515

@@ -247,6 +247,21 @@ def get_last_seen(ip)
247247
return last_seen
248248
end
249249

250+
def get_threat(ip)
251+
valid = !(IPAddr.new(ip) rescue nil).nil?
252+
if valid
253+
rec = get_record(ip)
254+
if !(rec.nil?)
255+
threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
256+
else
257+
threat = INVALID_IP_ADDRESS
258+
end
259+
else
260+
threat = INVALID_IP_ADDRESS
261+
end
262+
return threat
263+
end
264+
250265
def is_proxy(ip)
251266
valid = !(IPAddr.new(ip) rescue nil).nil?
252267
if valid
@@ -282,6 +297,7 @@ def get_all(ip)
282297
asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
283298
as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
284299
last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
300+
threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
285301
if self.db_index == 1
286302
isproxy = (rec.country_short == '-') ? 0 : 1
287303
else
@@ -299,6 +315,7 @@ def get_all(ip)
299315
asn = INVALID_IP_ADDRESS
300316
as = INVALID_IP_ADDRESS
301317
last_seen = INVALID_IP_ADDRESS
318+
threat = INVALID_IP_ADDRESS
302319
isproxy = -1
303320
end
304321
else
@@ -313,6 +330,7 @@ def get_all(ip)
313330
asn = INVALID_IP_ADDRESS
314331
as = INVALID_IP_ADDRESS
315332
last_seen = INVALID_IP_ADDRESS
333+
threat = INVALID_IP_ADDRESS
316334
isproxy = -1
317335
end
318336
results = {}
@@ -328,6 +346,7 @@ def get_all(ip)
328346
results['asn'] = asn
329347
results['as'] = as
330348
results['last_seen'] = last_seen
349+
results['threat'] = threat
331350
return results
332351
end
333352

lib/ip2proxy_ruby/i2p_database_config.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
class I2pDbConfig
22
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]
3+
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
4+
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4],
5+
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5],
6+
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6],
7+
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2],
8+
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7],
9+
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8],
10+
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9],
11+
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10],
12+
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11],
13+
:THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12]
1314
}
1415

1516
def self.setup_database(db_index)

0 commit comments

Comments
 (0)