ip2proxy_ruby 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e85aa655931de9dec06fe78849d14e570b6410859cf0db44d14eaec4788b65ab
4
- data.tar.gz: b11479694f3df231134bb86bcfbbb858d758b80bb73f59be2a5c45309372fbf9
3
+ metadata.gz: 11876f082eb12299523abfba314eedec46e9c21a77402a87e9893b64e1bfc4cb
4
+ data.tar.gz: b05171fa3e3b7a1edcd2864a501cd26a4516870209507cb23878785861cc9634
5
5
  SHA512:
6
- metadata.gz: 8a54a2ecc9cc1476f4695c3fac314f6df50c174b170e5b3a4a7c9a417cf46a5b1d8372378612eb40c1cd5b140baa22dd82f69fb71989d82a1c40421f9db35007
7
- data.tar.gz: fd0d1ef56dcd0c47d8180047f89ebb301195e1a9cdc09f1908661dc4a383c056363b3e50c19e81f9fe36b2f78c66d648efbf0fe63445dadae088535d83b90f39
6
+ metadata.gz: bbd818693fd97afaaf9abb6eb0de6e8235d584347309cac75d9c3c2a7f28e81c32f6b2cd2d227f74cd8058f82c688ba167aabadb7a04bdc279f7ab79dbfc632b
7
+ data.tar.gz: 2eb3b4766c5f7b28b477187f9bcdced970b7516e724f21639511734a6f3df92ffa578fb86bd752a8870515a05b7d0756221d58d540cb2d55a267b56cbdb14d6c
data/README.md CHANGED
@@ -2,27 +2,22 @@
2
2
  [![Total Downloads](https://img.shields.io/gem/dt/ip2proxy_ruby.svg)](https://rubygems.org/gems/ip2proxy_ruby)
3
3
 
4
4
  # IP2Proxy Ruby Library
5
-
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, last seen date and provider names.
7
-
8
- It lookup the proxy IP address from **IP2Proxy BIN Data** file. This data file can be downloaded at
9
-
10
- * Free IP2Proxy BIN Data: https://lite.ip2location.com
11
- * Commercial IP2Proxy BIN Data: https://www.ip2location.com/proxy-database
12
-
5
+ 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, last seen date and provider names. It lookup the proxy IP address from **IP2Proxy BIN Data** file or web service.
13
6
 
14
7
  For more details, please visit:
15
8
  [https://www.ip2location.com/ip2proxy/developers/ruby](https://www.ip2location.com/ip2proxy/developers/ruby)
16
9
 
17
- ## Methods
10
+ # Usage
11
+ You can check the **example.rb** file to learn more about usage.
18
12
 
19
- Below are the methods supported in this module.
13
+ ## BIN Database
14
+ Below is the description of the functions available in the **BIN Database** lookup.
20
15
 
21
16
  |Method Name|Description|
22
17
  |---|---|
23
18
  |open|Open the IP2Proxy BIN data with **File I/O** mode for lookup.|
24
19
  |close|Close and clean up the file pointer.|
25
- |get_package_version|Get the package version (1 to 10 for PX1 to PX11 respectively).|
20
+ |get_package_version|Get the package version (1 to 11 for PX1 to PX11 respectively).|
26
21
  |get_module_version|Get the module version.|
27
22
  |get_database_version|Get the database version.|
28
23
  |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>|
@@ -41,55 +36,14 @@ Below are the methods supported in this module.
41
36
  |get_threat|Return the threat types reported to proxy's IP address or domain name. Please see [Threat Type](#threat-type) for details.|
42
37
  |get_provider|Returns the VPN service provider name if available.|
43
38
 
44
- ## Usage
45
-
46
- ```
47
- require 'ip2proxy_ruby'
48
-
49
- # open IP2Proxy BIN database for proxy lookup
50
- i2p = Ip2proxy.new.open("./data/IP2PROXY-IP-PROXYTYPE-COUNTRY-REGION-CITY-ISP-DOMAIN-USAGETYPE-ASN-LASTSEEN-THREAT-RESIDENTIAL-PROVIDER.BIN")
51
-
52
- # get versioning information
53
- print 'Module Version: ' + i2p.get_module_version + "\n"
54
- print 'Package Version: ' + i2p.get_package_version + "\n"
55
- print 'Database Version: ' + i2p.get_database_version + "\n"
56
-
57
- # individual proxy data check
58
- print 'Is Proxy: ' + i2p.is_proxy('1.2.3.4').to_s + "\n"
59
- print 'Proxy Type: ' + i2p.get_proxytype('1.2.3.4') + "\n"
60
- print 'Country Code: ' + i2p.get_country_short('1.2.3.4') + "\n"
61
- print 'Country Name: ' + i2p.get_country_long('1.2.3.4') + "\n"
62
- print 'Region Name: ' + i2p.get_region('1.2.3.4') + "\n"
63
- print 'City Name: ' + i2p.get_city('1.2.3.4') + "\n"
64
- print 'ISP: ' + i2p.get_isp('1.2.3.4') + "\n"
65
- print 'Domain: ' + i2p.get_domain('1.2.3.4') + "\n"
66
- print 'Usage Type: ' + i2p.get_usagetype('1.2.3.4') + "\n"
67
- print 'ASN: ' + i2p.get_asn('1.2.3.4') + "\n"
68
- print 'AS: ' + i2p.get_as('1.2.3.4') + "\n"
69
- print 'Last Seen: ' + i2p.get_last_seen('1.2.3.4') + "\n"
70
- print 'Threat: ' + i2p.get_threat('1.2.3.4') + "\n"
71
- print 'Provider: ' + i2p.get_provider('1.2.3.4') + "\n"
72
-
73
- # single function to get all proxy data returned in array
74
- record = i2p.get_all('1.2.3.4')
75
- print 'is Proxy: ' + record['is_proxy'].to_s + "\n"
76
- print 'Proxy Type: ' + record['proxy_type'] + "\n"
77
- print 'Country Code: ' + record['country_short'] + "\n"
78
- print 'Country Name: ' + record['country_long'] + "\n"
79
- print 'Region Name: ' + record['region'] + "\n"
80
- print 'City Name: ' + record['city'] + "\n"
81
- print 'ISP: ' + record['isp'] + "\n"
82
- print 'Domain: ' + record['domain'] + "\n"
83
- print 'Usage Type: ' + record['usagetype'] + "\n"
84
- print 'ASN: ' + record['asn'] + "\n"
85
- print 'AS: ' + record['as'] + "\n"
86
- print 'Last Seen: ' + record['last_seen'] + "\n"
87
- print 'Threat: ' + record['threat'] + "\n"
88
- print 'Provider: ' + record['provider'] + "\n"
89
-
90
- # close IP2Proxy BIN database
91
- i2p.close()
92
- ```
39
+ ## Web Service
40
+ Below is the description of the functions available in the **Web Service** lookup.
41
+
42
+ | Function Name | Description |
43
+ |---|---|
44
+ | Constructor | Expect 3 input parameters:<ol><li>IP2Proxy API Key.</li><li>Package (PX1 - PX11)</li></li><li>Use HTTPS or HTTP</li></ol> |
45
+ | lookup | Return the proxy information in array.<ul><li>countryCode</li><li>countryName</li><li>regionName</li><li>cityName</li><li>isp</li><li>domain</li><li>usageType</li><li>asn</li><li>as</li><li>lastSeen</li><li>threat</li><li>proxyType</li><li>isProxy</li><li>provider</li><ul> |
46
+ | get_credit | Return remaining credit of the web service account. |
93
47
 
94
48
  ### Proxy Type
95
49
 
@@ -128,7 +82,17 @@ i2p.close()
128
82
  |SCANNER|Security Scanner or Attack|
129
83
  |BOTNET|Spyware or Malware|
130
84
 
131
- ## Support
85
+ # Dependencies
86
+
87
+ This library requires IP2Proxy BIN data file to function. You may download the BIN data file at
88
+ * IP2Proxy LITE BIN Data (Free): https://lite.ip2location.com
89
+ * IP2Proxy Commercial BIN Data (Comprehensive): https://www.ip2location.com/proxy-database
90
+
91
+ An outdated BIN database was provided in the library for your testing. You are recommended to visit the above links to download the latest BIN database.
92
+
93
+ You can also sign up for [IP2Proxy Web Service](https://www.ip2location.com/web-service/ip2proxy) to lookup by IP2Proxy API.
94
+
95
+ # Support
132
96
 
133
97
  Email: support@ip2location.com
134
98
  URL: [https://www.ip2location.com](https://www.ip2location.com)
data/example.rb CHANGED
@@ -42,4 +42,11 @@ print 'Threat: ' + record['threat'] + "\n"
42
42
  print 'Provider: ' + record['provider'] + "\n"
43
43
 
44
44
  # close IP2Proxy BIN database
45
- i2p.close()
45
+ i2p.close()
46
+
47
+ # Web Service
48
+ ws = Ip2proxyWebService.new('demo', 'PX11', true)
49
+ record = ws.lookup('1.2.3.4')
50
+ print record
51
+ print "\n"
52
+ print ws.get_credit()
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "ip2proxy_ruby"
5
- s.version = "3.1.0"
5
+ s.version = "3.2.0"
6
6
  s.authors = ["ip2location"]
7
7
  s.email = ["support@ip2location.com"]
8
8
 
data/lib/ip2proxy_ruby.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'bindata'
2
2
  require 'ipaddr'
3
+ require 'net/http'
4
+ require 'json'
3
5
  require_relative 'ip2proxy_ruby/ip2proxy_config'
4
6
  require_relative 'ip2proxy_ruby/i2p_database_config'
5
7
  require_relative 'ip2proxy_ruby/i2p_string_data'
@@ -9,7 +11,7 @@ require_relative 'ip2proxy_ruby/ip2proxy_record'
9
11
  class Ip2proxy
10
12
  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, :last_err_msg
11
13
 
12
- VERSION = '3.1.0'
14
+ VERSION = '3.2.0'
13
15
  FIELD_NOT_SUPPORTED = 'NOT SUPPORTED'
14
16
  INVALID_IP_ADDRESS = 'INVALID IP ADDRESS'
15
17
  INVALID_BIN_DATABASE = 'Incorrect IP2Proxy BIN file format. Please make sure that you are using the latest IP2Proxy BIN file.'
@@ -469,4 +471,55 @@ class Ip2proxy
469
471
 
470
472
  private :get_record, :bsearch, :get_from_to, :read32, :readipv6
471
473
 
474
+ end
475
+
476
+ class Ip2proxyWebService
477
+ attr_accessor :ws_api_key, :ws_package, :ws_use_ssl
478
+
479
+ def initialize(api_key, package, use_ssl)
480
+ if !api_key.match(/^[0-9A-Z]{10}$/) && api_key != 'demo'
481
+ raise Exception.new "Please provide a valid IP2Proxy web service API key."
482
+ end
483
+ if !package.match(/^PX[0-9]+$/)
484
+ package = 'PX1'
485
+ end
486
+ if use_ssl == ''
487
+ use_ssl = true
488
+ end
489
+ self.ws_api_key = api_key
490
+ self.ws_package = package
491
+ self.ws_use_ssl = use_ssl
492
+ end
493
+
494
+ def lookup(ip)
495
+ if self.ws_use_ssl
496
+ response = Net::HTTP.get(URI("https://api.ip2proxy.com/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json"))
497
+ else
498
+ response = Net::HTTP.get(URI("http://api.ip2proxy.com/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json"))
499
+ end
500
+ parsed_response = JSON.parse(response)
501
+ if parsed_response.nil?
502
+ return false
503
+ end
504
+ if parsed_response["response"] != "OK"
505
+ raise Exception.new "Error: " + parsed_response["response"]
506
+ end
507
+ return parsed_response
508
+ end
509
+
510
+ def get_credit()
511
+ if self.ws_use_ssl
512
+ response = Net::HTTP.get(URI("https://api.ip2proxy.com/?key=" + self.ws_api_key + "&check=true"))
513
+ else
514
+ response = Net::HTTP.get(URI("http://api.ip2proxy.com/?key=" + self.ws_api_key + "&check=true"))
515
+ end
516
+ parsed_response = JSON.parse(response)
517
+ if parsed_response.nil?
518
+ return 0
519
+ end
520
+ if parsed_response["response"].nil?
521
+ return 0
522
+ end
523
+ return parsed_response["response"]
524
+ end
472
525
  end
@@ -106,7 +106,7 @@ describe "Ip2proxy" do
106
106
  it "work correctly with get_module_version" do
107
107
  i2p = Ip2proxy.new.open(File.dirname(__FILE__) + "/assets/PX11.SAMPLE.BIN")
108
108
  record = i2p.get_module_version()
109
- expect(record).to eq '3.1.0'
109
+ expect(record).to eq '3.2.0'
110
110
  end
111
111
 
112
112
  it "work correctly with get_package_version" do
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: 3.1.0
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: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata