ip2proxy_ruby 3.1.0 → 3.3.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: 30a6be5f8b9be3046d9450d970a996f61f07d49c35dc8ad44036f534457e8cb1
4
+ data.tar.gz: 7b2babc2892f5f6c29d5038ab86d23da675e7cd0acadac7bf035e2ab2f2fff39
5
5
  SHA512:
6
- metadata.gz: 8a54a2ecc9cc1476f4695c3fac314f6df50c174b170e5b3a4a7c9a417cf46a5b1d8372378612eb40c1cd5b140baa22dd82f69fb71989d82a1c40421f9db35007
7
- data.tar.gz: fd0d1ef56dcd0c47d8180047f89ebb301195e1a9cdc09f1908661dc4a383c056363b3e50c19e81f9fe36b2f78c66d648efbf0fe63445dadae088535d83b90f39
6
+ metadata.gz: 0304a809be3a8fc3e87265b2c93811a91aa6595d1ce535132db963d114a6ec4b9e2102dc2418f99d3812ada25cc18fff631065387e9b1aff3dad777ac1c598c8
7
+ data.tar.gz: 6faecc7b8ca06d0b0221fa926d587d45bd9e447f881f1b0e7a84e3873adb6a7af831ba9d37fe5105f6f7e46e82113e89f968735c30d401a67dafa6fcc4c85889
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021 IP2Location ( support@ip2location.com )
1
+ Copyright (c) 2022 IP2Location ( support@ip2location.com )
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,27 +2,24 @@
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.
12
+
13
+ ## BIN Database
14
+ An outdated BIN database was provided in the library for your testing. You are recommended to visit the [links](#dependencies) to download the latest BIN database and save it in the ```rb``` folder.
18
15
 
19
- Below are the methods supported in this module.
16
+ Below is the description of the functions available in the **BIN Database** lookup.
20
17
 
21
18
  |Method Name|Description|
22
19
  |---|---|
23
20
  |open|Open the IP2Proxy BIN data with **File I/O** mode for lookup.|
24
21
  |close|Close and clean up the file pointer.|
25
- |get_package_version|Get the package version (1 to 10 for PX1 to PX11 respectively).|
22
+ |get_package_version|Get the package version (1 to 11 for PX1 to PX11 respectively).|
26
23
  |get_module_version|Get the module version.|
27
24
  |get_database_version|Get the database version.|
28
25
  |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 +38,14 @@ Below are the methods supported in this module.
41
38
  |get_threat|Return the threat types reported to proxy's IP address or domain name. Please see [Threat Type](#threat-type) for details.|
42
39
  |get_provider|Returns the VPN service provider name if available.|
43
40
 
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
- ```
41
+ ## Web Service
42
+ Below is the description of the functions available in the **Web Service** lookup.
43
+
44
+ | Function Name | Description |
45
+ |---|---|
46
+ | Constructor | Expect 3 input parameters:<ol><li>IP2Proxy API Key.</li><li>Package (PX1 - PX11)</li></li><li>Use HTTPS or HTTP</li></ol> |
47
+ | 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> |
48
+ | get_credit | Return remaining credit of the web service account. |
93
49
 
94
50
  ### Proxy Type
95
51
 
@@ -128,7 +84,15 @@ i2p.close()
128
84
  |SCANNER|Security Scanner or Attack|
129
85
  |BOTNET|Spyware or Malware|
130
86
 
131
- ## Support
87
+ # Dependencies
88
+
89
+ This library requires IP2Proxy BIN data file to function. You may download the BIN data file at
90
+ * IP2Proxy LITE BIN Data (Free): https://lite.ip2location.com
91
+ * IP2Proxy Commercial BIN Data (Comprehensive): https://www.ip2location.com/proxy-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.3.0"
6
6
  s.authors = ["ip2location"]
7
7
  s.email = ["support@ip2location.com"]
8
8
 
@@ -51,18 +51,18 @@ Gem::Specification.new do |s|
51
51
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
52
  s.add_runtime_dependency(%q<bindata>, [">= 0"])
53
53
  s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
54
- s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
54
+ s.add_development_dependency(%q<rdoc>, [">= 6.3.1"])
55
55
  s.add_development_dependency(%q<bundler>, [">= 1.2.0"])
56
56
  else
57
57
  s.add_dependency(%q<bindata>, [">= 0"])
58
58
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
59
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
59
+ s.add_dependency(%q<rdoc>, [">= 6.3.1"])
60
60
  s.add_dependency(%q<bundler>, [">= 1.2.0"])
61
61
  end
62
62
  else
63
63
  s.add_dependency(%q<bindata>, [">= 0"])
64
64
  s.add_dependency(%q<rspec>, ["~> 2.8.0"])
65
- s.add_dependency(%q<rdoc>, ["~> 3.12"])
65
+ s.add_dependency(%q<rdoc>, [">= 6.3.1"])
66
66
  s.add_dependency(%q<bundler>, [">= 1.2.0"])
67
67
  end
68
68
  end
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.3.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.'
@@ -24,7 +26,7 @@ class Ip2proxy
24
26
  self.file = File.open(File.expand_path url, 'rb')
25
27
  rescue
26
28
  self.last_err_msg = 'Ip2proxy.new.open() error in opening ' + url +'.'
27
- abort('Ip2proxy.new.open() error in opening ' + url +'.')
29
+ abort('Ip2proxy.new.open() error in opening ' + url + '. No such file in the /your_ip2proxy_ruby_library_path/rb/ folder.')
28
30
  else
29
31
  end
30
32
  i2p = Ip2proxyConfig.read(file)
@@ -99,8 +101,7 @@ class Ip2proxy
99
101
  ipnum = realipno - 1
100
102
  end
101
103
  end
102
- low = read32(indexpos)
103
- high = read32(indexpos + 4)
104
+ low, high = read32x2(indexpos)
104
105
  return self.record = bsearch(low, high, ipnum, self.base_addr, col_length)
105
106
  else
106
107
  return self.record = bsearch(0, self.count, ipnum, self.base_addr, col_length)
@@ -417,11 +418,12 @@ class Ip2proxy
417
418
  end
418
419
 
419
420
  def get_from_to(mid, base_addr, col_length)
420
- from_base = ( base_addr + mid * (col_length + (v4 ? 0 : 12)))
421
+ from_base = (base_addr + mid * (col_length + (v4 ? 0 : 12)))
422
+ data_length = col_length + (v4 ? 4 : (12 + 16))
421
423
  file.seek(from_base)
422
- ip_from = v4 ? file.read(4).unpack('V').first : readipv6(file)
423
- file.seek(from_base + col_length + (v4 ? 0 : 12))
424
- ip_to = v4 ? file.read(4).unpack('V').first : readipv6(file)
424
+ data_read = file.read(data_length)
425
+ ip_from = v4 ? data_read[0..3].unpack('V').first : readipv6(data_read[0..15].unpack('V*'))
426
+ ip_to = v4 ? data_read[(data_length - 4)..(data_length - 1)].unpack('V').first : readipv6(data_read[(data_length - 16)..(data_length - 1)].unpack('V*'))
425
427
  [ip_from, ip_to]
426
428
  end
427
429
 
@@ -457,16 +459,69 @@ class Ip2proxy
457
459
  [ipv, ipnum]
458
460
  end
459
461
 
460
- def read32(indexp)
462
+ def read32x2(indexp)
461
463
  file.seek(indexp - 1)
462
- return file.read(4).unpack('V').first
464
+ data_read = file.read(8)
465
+ data1 = data_read[0..3].unpack('V').first
466
+ data2 = data_read[4..7].unpack('V').first
467
+ return [data1, data2]
463
468
  end
464
469
 
465
- def readipv6(filer)
466
- parts = filer.read(16).unpack('V*')
470
+ def readipv6(parts)
467
471
  return parts[0] + parts[1] * 4294967296 + parts[2] * 4294967296**2 + parts[3] * 4294967296**3
468
472
  end
469
473
 
470
- private :get_record, :bsearch, :get_from_to, :read32, :readipv6
474
+ private :get_record, :bsearch, :get_from_to, :read32x2, :readipv6
471
475
 
476
+ end
477
+
478
+ class Ip2proxyWebService
479
+ attr_accessor :ws_api_key, :ws_package, :ws_use_ssl
480
+
481
+ def initialize(api_key, package, use_ssl)
482
+ if !api_key.match(/^[0-9A-Z]{10}$/) && api_key != 'demo'
483
+ raise Exception.new "Please provide a valid IP2Proxy web service API key."
484
+ end
485
+ if !package.match(/^PX[0-9]+$/)
486
+ package = 'PX1'
487
+ end
488
+ if use_ssl == ''
489
+ use_ssl = true
490
+ end
491
+ self.ws_api_key = api_key
492
+ self.ws_package = package
493
+ self.ws_use_ssl = use_ssl
494
+ end
495
+
496
+ def lookup(ip)
497
+ if self.ws_use_ssl
498
+ response = Net::HTTP.get(URI("https://api.ip2proxy.com/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json"))
499
+ else
500
+ response = Net::HTTP.get(URI("http://api.ip2proxy.com/?key=" + self.ws_api_key + "&ip=" + ip + "&package=" + self.ws_package + "&format=json"))
501
+ end
502
+ parsed_response = JSON.parse(response)
503
+ if parsed_response.nil?
504
+ return false
505
+ end
506
+ if parsed_response["response"] != "OK"
507
+ raise Exception.new "Error: " + parsed_response["response"]
508
+ end
509
+ return parsed_response
510
+ end
511
+
512
+ def get_credit()
513
+ if self.ws_use_ssl
514
+ response = Net::HTTP.get(URI("https://api.ip2proxy.com/?key=" + self.ws_api_key + "&check=true"))
515
+ else
516
+ response = Net::HTTP.get(URI("http://api.ip2proxy.com/?key=" + self.ws_api_key + "&check=true"))
517
+ end
518
+ parsed_response = JSON.parse(response)
519
+ if parsed_response.nil?
520
+ return 0
521
+ end
522
+ if parsed_response["response"].nil?
523
+ return 0
524
+ end
525
+ return parsed_response["response"]
526
+ end
472
527
  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.3.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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ip2location
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-17 00:00:00.000000000 Z
11
+ date: 2022-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rdoc
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '3.12'
47
+ version: 6.3.1
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '3.12'
54
+ version: 6.3.1
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -104,7 +104,7 @@ metadata:
104
104
  bug_tracker_uri: https://github.com/ip2location/ip2proxy-ruby/issues
105
105
  homepage_uri: https://www.ip2location.com
106
106
  source_code_uri: https://github.com/ip2location/ip2proxy-ruby
107
- post_install_message:
107
+ post_install_message:
108
108
  rdoc_options: []
109
109
  require_paths:
110
110
  - lib
@@ -119,9 +119,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.7.6.2
124
- signing_key:
122
+ rubygems_version: 3.2.33
123
+ signing_key:
125
124
  specification_version: 4
126
125
  summary: IP2Proxy Ruby library
127
126
  test_files: []