proxy_pool 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.txt +21 -0
- data/README.md +61 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/proxy_pool.rb +31 -0
- data/lib/proxy_pool/dealer.rb +87 -0
- data/lib/proxy_pool/version.rb +3 -0
- data/proxy_pool.gemspec +35 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 78ea0558c9c726da9a0ab591716246ae7b313d4f58e277661595edb5e52374f6
|
4
|
+
data.tar.gz: 5bc6e6de2724d8c605d5785eec02a56f08ca5f01ffd6698db7d1a080ba0a482f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 814a8c138f52168e3baacdcc0362ede1f2c741533169086360740bd74d0aa920bcc934c7311541d898a654dc770983d14d3770afd92a5d2d6258213e3873846a
|
7
|
+
data.tar.gz: 002e2b3630aeb72e2b5a6bcd6f8ac8520e229d6cdbbf017614b3b688c1f3455042a099bbbf4009af555fbdefcb830cf9facc936fb03a9906e553f103b2b9cf09
|
data/.gitignore
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
proxy_pool
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.6.3
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
proxy_pool (0.1.0)
|
5
|
+
http (~> 4.1, >= 4.1.1)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.6.0)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
domain_name (0.5.20190701)
|
13
|
+
unf (>= 0.0.5, < 1.0.0)
|
14
|
+
http (4.1.1)
|
15
|
+
addressable (~> 2.3)
|
16
|
+
http-cookie (~> 1.0)
|
17
|
+
http-form_data (~> 2.0)
|
18
|
+
http_parser.rb (~> 0.6.0)
|
19
|
+
http-cookie (1.0.3)
|
20
|
+
domain_name (~> 0.5)
|
21
|
+
http-form_data (2.1.1)
|
22
|
+
http_parser.rb (0.6.0)
|
23
|
+
minitest (5.11.3)
|
24
|
+
public_suffix (3.1.1)
|
25
|
+
rake (10.5.0)
|
26
|
+
unf (0.1.4)
|
27
|
+
unf_ext
|
28
|
+
unf_ext (0.0.7.6)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 2.0)
|
35
|
+
minitest (~> 5.0)
|
36
|
+
proxy_pool!
|
37
|
+
rake (~> 10.0)
|
38
|
+
|
39
|
+
BUNDLED WITH
|
40
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 TODO: Write your name
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# ProxyPool
|
2
|
+
|
3
|
+
ProxyPool is a wrapper for [fate0/proxylist](https://github.com/fate0/proxylist)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'proxy_pool'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install proxy_pool
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Get anonymous proxy randomly:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'proxy_pool'
|
27
|
+
|
28
|
+
ProxyPool.get_anonymous_proxy
|
29
|
+
=> {"country"=>"RU", "anonymity"=>"high_anonymous", "from"=>"txt", "type"=>"https", "export_address"=>["94.242.58.14", "94.242.58.14"], "port"=>1448, "host"=>"94.242.58.14", "response_time"=>1.7}
|
30
|
+
```
|
31
|
+
|
32
|
+
Get transparent proxy randomly:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'proxy_pool'
|
36
|
+
|
37
|
+
ProxyPool.get_transparent_proxy
|
38
|
+
=> {"country"=>"ID", "anonymity"=>"anonymous", "from"=>"txt", "type"=>"http", "export_address"=>["35.192.136.167", "118.97.191.162", "35.192.136.167"], "port"=>80, "host"=>"118.97.191.162", "response_time"=>3.04}
|
39
|
+
```
|
40
|
+
|
41
|
+
Use filter:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'proxy_pool'
|
45
|
+
|
46
|
+
ProxyPool.get_anonymous_proxy(type: 'https', country: 'ID', port: 80, from: 'txt')
|
47
|
+
```
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/zt2/proxy_pool.
|
58
|
+
|
59
|
+
## License
|
60
|
+
|
61
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "proxy_pool"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/proxy_pool.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module ProxyPool
|
2
|
+
#
|
3
|
+
# Errors
|
4
|
+
#
|
5
|
+
|
6
|
+
# Base error
|
7
|
+
class Error < StandardError;
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'proxy_pool/version'
|
11
|
+
require 'proxy_pool/dealer'
|
12
|
+
|
13
|
+
class << self
|
14
|
+
# Get anonymous proxy from pool randomly
|
15
|
+
#
|
16
|
+
# @param filter [Hash] Filter
|
17
|
+
# @return [Hash] Proxy
|
18
|
+
def get_anonymous_proxy(filter={})
|
19
|
+
ProxyPool::Dealer.instance.get(true, filter)
|
20
|
+
end
|
21
|
+
|
22
|
+
# Get transparent proxy from pool randomly
|
23
|
+
#
|
24
|
+
# @param filter [Hash] Filter
|
25
|
+
# @return [Hash] Proxy
|
26
|
+
def get_transparent_proxy(filter={})
|
27
|
+
ProxyPool::Dealer.instance.get(false, filter)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
#
|
2
|
+
# Standard library
|
3
|
+
#
|
4
|
+
require 'json'
|
5
|
+
require 'singleton'
|
6
|
+
|
7
|
+
#
|
8
|
+
# Third-party library
|
9
|
+
#
|
10
|
+
require 'http'
|
11
|
+
|
12
|
+
module ProxyPool
|
13
|
+
#
|
14
|
+
# Pool
|
15
|
+
#
|
16
|
+
class Dealer
|
17
|
+
include Singleton
|
18
|
+
|
19
|
+
# HTTP error
|
20
|
+
class HTTPError < Error;
|
21
|
+
end
|
22
|
+
|
23
|
+
# Parse error
|
24
|
+
class ParseError < Error;
|
25
|
+
end
|
26
|
+
|
27
|
+
# Filter error
|
28
|
+
class FilterError < Error;
|
29
|
+
end
|
30
|
+
|
31
|
+
attr_reader :transparent_pools, :anonymous_pools
|
32
|
+
|
33
|
+
# Update to latest proxy list from fate0/proxylist
|
34
|
+
#
|
35
|
+
def update
|
36
|
+
@transparent_pools = []
|
37
|
+
@anonymous_pools = []
|
38
|
+
|
39
|
+
res = HTTP.get 'https://raw.githubusercontent.com/fate0/proxylist/master/proxy.list'
|
40
|
+
raise HTTPError, "invalid http code #{res.code}" if res.code != 200
|
41
|
+
|
42
|
+
res.body.to_s.split("\n").each {|line| _pool_parse(line)}
|
43
|
+
end
|
44
|
+
|
45
|
+
# Get a random proxy
|
46
|
+
#
|
47
|
+
# @param anonymous [TrueClass | FalseClass] Return high anonymous proxy if true
|
48
|
+
# @param filter [Hash] Filter
|
49
|
+
# @return [Hash] Proxy
|
50
|
+
def get(anonymous=true, filter={})
|
51
|
+
update if @transparent_pools.nil? && @anonymous_pools.nil?
|
52
|
+
|
53
|
+
target_pools = if anonymous
|
54
|
+
@anonymous_pools
|
55
|
+
else
|
56
|
+
@transparent_pools
|
57
|
+
end
|
58
|
+
filter.each_pair { |k, v| target_pools = _pool_filter(target_pools, k.to_s, v) }
|
59
|
+
|
60
|
+
target_pools.sample
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def _pool_parse(line)
|
66
|
+
proxy = JSON.parse(line)
|
67
|
+
raise ParseError, "no anonymity field: #{line}" unless proxy.key?('anonymity')
|
68
|
+
|
69
|
+
case proxy['anonymity']
|
70
|
+
when 'high_anonymous'
|
71
|
+
@anonymous_pools << proxy
|
72
|
+
else
|
73
|
+
@transparent_pools << proxy
|
74
|
+
end
|
75
|
+
rescue JSON::ParserError
|
76
|
+
raise ParseError, "JSON parser error when parsing #{line}"
|
77
|
+
end
|
78
|
+
|
79
|
+
def _pool_filter(proxy_pools, key, value)
|
80
|
+
proxy_pools.select do |proxy|
|
81
|
+
raise FilterError, "invalid filter: #{key}" unless proxy.key?(key)
|
82
|
+
proxy[key] == value
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
data/proxy_pool.gemspec
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "proxy_pool/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "proxy_pool"
|
7
|
+
spec.version = ProxyPool::VERSION
|
8
|
+
spec.authors = ["hi_ztz"]
|
9
|
+
spec.email = ["hi_ztz@protonmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{select a ip from proxy list randomly}
|
12
|
+
spec.description = %q{proxy_pool can give you free and random proxy ip}
|
13
|
+
spec.homepage = "https://github.com/zt2/proxy_pool"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
17
|
+
|
18
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
33
|
+
|
34
|
+
spec.add_runtime_dependency 'http', '~> 4.1', '>= 4.1.1'
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: proxy_pool
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- hi_ztz
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-07-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '5.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: http
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '4.1'
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 4.1.1
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - "~>"
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '4.1'
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 4.1.1
|
75
|
+
description: proxy_pool can give you free and random proxy ip
|
76
|
+
email:
|
77
|
+
- hi_ztz@protonmail.com
|
78
|
+
executables: []
|
79
|
+
extensions: []
|
80
|
+
extra_rdoc_files: []
|
81
|
+
files:
|
82
|
+
- ".gitignore"
|
83
|
+
- ".ruby-gemset"
|
84
|
+
- ".ruby-version"
|
85
|
+
- ".travis.yml"
|
86
|
+
- Gemfile
|
87
|
+
- Gemfile.lock
|
88
|
+
- LICENSE.txt
|
89
|
+
- README.md
|
90
|
+
- Rakefile
|
91
|
+
- bin/console
|
92
|
+
- bin/setup
|
93
|
+
- lib/proxy_pool.rb
|
94
|
+
- lib/proxy_pool/dealer.rb
|
95
|
+
- lib/proxy_pool/version.rb
|
96
|
+
- proxy_pool.gemspec
|
97
|
+
homepage: https://github.com/zt2/proxy_pool
|
98
|
+
licenses:
|
99
|
+
- MIT
|
100
|
+
metadata:
|
101
|
+
allowed_push_host: https://rubygems.org
|
102
|
+
homepage_uri: https://github.com/zt2/proxy_pool
|
103
|
+
source_code_uri: https://github.com/zt2/proxy_pool
|
104
|
+
post_install_message:
|
105
|
+
rdoc_options: []
|
106
|
+
require_paths:
|
107
|
+
- lib
|
108
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
requirements: []
|
119
|
+
rubygems_version: 3.0.3
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: select a ip from proxy list randomly
|
123
|
+
test_files: []
|