Skip to content

Commit

Permalink
Added supports for threats (PX9) & residential proxies (PX10).
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Aug 7, 2020
1 parent 7f27228 commit 9df6cdf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 24 deletions.
34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# IP2Proxy Ruby Library

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.
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.

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

Expand All @@ -22,12 +22,12 @@ Below are the methods supported in this module.
|---|---|
|open|Open the IP2Proxy BIN data with **File I/O** mode for lookup.|
|close|Close and clean up the file pointer.|
|get_package_version|Get the package version (1 to 8 for PX1 to PX8 respectively).|
|get_package_version|Get the package version (1 to 10 for PX1 to PX10 respectively).|
|get_module_version|Get the module version.|
|get_database_version|Get the database version.|
|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>|
|get_all|Return the proxy information in array.|
|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|
|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|
|get_country_short|Return the ISO3166-1 country code (2-digits) of the proxy.|
|get_country_long|Return the ISO3166-1 country name of the proxy.|
|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|
Expand All @@ -38,14 +38,15 @@ Below are the methods supported in this module.
|get_asn|Return the autonomous system number (ASN) of proxy's IP address or domain name.|
|get_as|Return the autonomous system (AS) name of proxy's IP address or domain name.|
|get_last_seen|Return the last seen days ago value of proxy's IP address or domain name.|
|get_threat|Return the threat types reported to proxy's IP address or domain name. Please see [Threat Type](#threat-type) for details.|

## Usage

```
require 'ip2proxy_ruby'
# open IP2Proxy BIN database for proxy lookup
i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN.BIN")
i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL.BIN")
# get versioning information
print 'Module Version: ' + i2p.get_module_version + "\n"
Expand All @@ -65,6 +66,7 @@ print 'Usage Type: ' + i2p.get_usagetype('1.2.3.4') + "\n"
print 'ASN: ' + i2p.get_asn('1.2.3.4') + "\n"
print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
# single function to get all proxy data returned in array
record = i2p.get_all('1.2.3.4')
Expand All @@ -80,6 +82,7 @@ print 'Usage Type: ' + record['usagetype'] + "\n"
print 'ASN: ' + record['asn'] + "\n"
print 'AS: ' + record['as'] + "\n"
print 'Last Seen: ' + record['last_seen'] + "\n"
print 'Threat: ' + record['threat'] + "\n"
# close IP2Proxy BIN database
i2p.close()
Expand All @@ -89,12 +92,13 @@ i2p.close()

|Proxy Type|Description|
|---|---|
|VPN|Anonymizing VPN services.|
|TOR|Tor Exit Nodes.|
|PUB|Public Proxies.|
|WEB|Web Proxies.|
|DCH|Hosting Providers/Data Center.|
|SES|Search Engine Robots.
|VPN|Anonymizing VPN services|
|TOR|Tor Exit Nodes|
|PUB|Public Proxies|
|WEB|Web Proxies|
|DCH|Hosting Providers/Data Center|
|SES|Search Engine Robots|
|RES|Residential Proxies [PX10+]|

### Usage Type

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

### Threat Type

|Threat Type|Description|
|---|---|
|SPAM|Spammer|
|SCANNER|Security Scanner or Attack|
|BOTNET|Spyware or Malware|

## Support

Email: [email protected]
Email: [email protected]
URL: [https://www.ip2location.com](https://www.ip2location.com)
2 changes: 2 additions & 0 deletions example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
print 'ASN: ' + i2p.get_asn('1.2.3.4') + "\n"
print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"

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

# close IP2Proxy BIN database
i2p.close()
4 changes: 2 additions & 2 deletions ip2proxy_ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

Gem::Specification.new do |s|
s.name = "ip2proxy_ruby"
s.version = "2.1.0"
s.version = "3.0.0"
s.authors = ["ip2location"]
s.email = ["[email protected]"]

s.summary = "IP2Proxy Ruby library"
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."
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."
s.homepage = "https://github.com/ip2location/ip2proxy-ruby"
s.licenses = ["MIT"]
s.require_paths = ["lib"]
Expand Down
21 changes: 20 additions & 1 deletion lib/ip2proxy_ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Ip2proxy
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

VERSION = '2.1.0'
VERSION = '3.0.0'
FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'

Expand Down Expand Up @@ -247,6 +247,21 @@ def get_last_seen(ip)
return last_seen
end

def get_threat(ip)
valid = !(IPAddr.new(ip) rescue nil).nil?
if valid
rec = get_record(ip)
if !(rec.nil?)
threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
else
threat = INVALID_IP_ADDRESS
end
else
threat = INVALID_IP_ADDRESS
end
return threat
end

def is_proxy(ip)
valid = !(IPAddr.new(ip) rescue nil).nil?
if valid
Expand Down Expand Up @@ -282,6 +297,7 @@ def get_all(ip)
asn = (defined?(rec.asn) && rec.asn != '') ? rec.asn : FIELD_NOT_SUPPORTED
as = (defined?(rec.as) && rec.as != '') ? rec.as : FIELD_NOT_SUPPORTED
last_seen = (defined?(rec.lastseen) && rec.lastseen != '') ? rec.lastseen : FIELD_NOT_SUPPORTED
threat = (defined?(rec.threat) && rec.threat != '') ? rec.threat : FIELD_NOT_SUPPORTED
if self.db_index == 1
isproxy = (rec.country_short == '-') ? 0 : 1
else
Expand All @@ -299,6 +315,7 @@ def get_all(ip)
asn = INVALID_IP_ADDRESS
as = INVALID_IP_ADDRESS
last_seen = INVALID_IP_ADDRESS
threat = INVALID_IP_ADDRESS
isproxy = -1
end
else
Expand All @@ -313,6 +330,7 @@ def get_all(ip)
asn = INVALID_IP_ADDRESS
as = INVALID_IP_ADDRESS
last_seen = INVALID_IP_ADDRESS
threat = INVALID_IP_ADDRESS
isproxy = -1
end
results = {}
Expand All @@ -328,6 +346,7 @@ def get_all(ip)
results['asn'] = asn
results['as'] = as
results['last_seen'] = last_seen
results['threat'] = threat
return results
end

Expand Down
21 changes: 11 additions & 10 deletions lib/ip2proxy_ruby/i2p_database_config.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
class I2pDbConfig
COLUMNS = {
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3],
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4],
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5],
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6],
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2],
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7],
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8],
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9],
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10],
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11]
:COUNTRY => [0, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3],
:REGION => [0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4],
:CITY => [0, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5],
:ISP => [0, 0, 0, 0, 6, 6, 6, 6, 6, 6, 6],
:PROXYTYPE => [0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2],
:DOMAIN => [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7],
:USAGETYPE => [0, 0, 0, 0, 0, 0, 8, 8, 8, 8, 8],
:ASN => [0, 0, 0, 0, 0, 0, 0, 9, 9, 9, 9],
:AS => [0, 0, 0, 0, 0, 0, 0, 10, 10, 10, 10],
:LASTSEEN => [0, 0, 0, 0, 0, 0, 0, 0, 11, 11, 11],
:THREAT => [0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 12]
}

def self.setup_database(db_index)
Expand Down

0 comments on commit 9df6cdf

Please sign in to comment.