Class: Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = "localhost", port = 8080, options = {}, credentials = {}) ⇒ Proxy

Returns a new instance of Proxy.



10
11
12
13
14
15
16
17
# File 'lib/proxy.rb', line 10

def initialize(host="localhost",port=8080,options={},credentials={})
	@host 				= host
	@port 				= port
	@type 				= options[:type] || "http"
	@timeout 			= options[:timeout].to_i || 10
	@credentials 	= credentials
	@config				= options
end

Instance Attribute Details

#timeoutObject (readonly)

Returns the value of attribute timeout.



8
9
10
# File 'lib/proxy.rb', line 8

def timeout
  @timeout
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/proxy.rb', line 7

def type
  @type
end

Instance Method Details

#change_ipObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/proxy.rb', line 23

def change_ip
	if @config[:tor]
		
		if @node.nil?
			@node = Tor::Controller.new(:host => @credentials[:telnet_host], :port => @credentials[:telnet_port])
		end

		if !@node.authenticated?
			@node.authenticate(@credentials[:telnet_passwd])
		end

		@node.signal("NEWNYM")
	end
end

#get_ipObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/proxy.rb', line 38

def get_ip
	Typhoeus::Config.user_agent = UserAgents.rand()

	response = Typhoeus::Request.new("http://checkip.amazonaws.com/", 
		timeout: 		@timeout,
		proxy: 			self.url,
		proxytype: 	@type).run
	
	return response.response_body.gsub("\n", '').strip
end

#urlObject



19
20
21
# File 'lib/proxy.rb', line 19

def url
	return @host.to_s+":"+@port.to_s
end