tor-privoxy 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/tor-privoxy.rb +2 -0
- data/lib/tor-privoxy/agent.rb +41 -0
- data/lib/tor-privoxy/switcher.rb +23 -0
- metadata +61 -0
data/lib/tor-privoxy.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'net/telnet'
|
2
|
+
require 'mechanize'
|
3
|
+
|
4
|
+
module TorPrivoxy
|
5
|
+
class Agent
|
6
|
+
def initialize host, pass, control, &callback
|
7
|
+
@proxy = Switcher.new host, pass, control
|
8
|
+
@mechanize = Mechanize.new
|
9
|
+
@mechanize.set_proxy(@proxy.host, @proxy.port)
|
10
|
+
@callback = callback
|
11
|
+
@callback.call
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing method, *args, &block
|
15
|
+
begin
|
16
|
+
@mechanize.send method, *args, &block
|
17
|
+
rescue Mechanize::ResponseCodeError # 403 etc
|
18
|
+
switch_circuit
|
19
|
+
retry
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def switch_circuit
|
24
|
+
localhost = Net::Telnet::new('Host' => @proxy.host, 'Port' => @proxy.control_port,
|
25
|
+
'Timeout' => 2, 'Prompt' => /250 OK\n/)
|
26
|
+
localhost.cmd("AUTHENTICATE \"#{@proxy.pass}\"")
|
27
|
+
localhost.cmd('signal NEWNYM')
|
28
|
+
localhost.close
|
29
|
+
|
30
|
+
@proxy.next
|
31
|
+
@mechanize = Mechanize.new
|
32
|
+
@mechanize.set_proxy(@proxy.host, @proxy.port)
|
33
|
+
|
34
|
+
@callback.call
|
35
|
+
end
|
36
|
+
|
37
|
+
def ip
|
38
|
+
@mechanize.get('http://ifconfig.me/ip').body
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TorPrivoxy
|
2
|
+
class Switcher
|
3
|
+
attr_reader :host, :pass
|
4
|
+
|
5
|
+
def initialize host, pass, control
|
6
|
+
@host, @pass, @control = host, pass, control
|
7
|
+
@current = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def next
|
11
|
+
@current = @current + 1
|
12
|
+
@current = 0 if @current >= @control.size
|
13
|
+
end
|
14
|
+
|
15
|
+
def port
|
16
|
+
@control.keys[@current]
|
17
|
+
end
|
18
|
+
|
19
|
+
def control_port
|
20
|
+
@control[port]
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tor-privoxy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Phil Pirozhkov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-11 00:00:00.000000000 +04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
requirement: &82474660 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *82474660
|
26
|
+
description: Mechanize wrapper to work via Tor/Privoxy with endpoint switching ability
|
27
|
+
email:
|
28
|
+
- pirj@mail.ru
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/tor-privoxy.rb
|
34
|
+
- lib/tor-privoxy/agent.rb
|
35
|
+
- lib/tor-privoxy/switcher.rb
|
36
|
+
has_rdoc: true
|
37
|
+
homepage: https://github.com/pirj/tor-privoxy
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.6.2
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: Mechanize wrapper to work via Tor/Privoxy with endpoint switching ability
|
61
|
+
test_files: []
|