Class: Proxy
- Inherits:
-
Object
- Object
- Proxy
- Defined in:
- lib/proxy.rb
Instance Attribute Summary collapse
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #change_ip ⇒ Object
- #get_ip ⇒ Object
-
#initialize(host = "localhost", port = 8080, options = {}, credentials = {}) ⇒ Proxy
constructor
A new instance of Proxy.
- #url ⇒ Object
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,={},credentials={}) @host = host @port = port @type = [:type] || "http" @timeout = [:timeout].to_i || |
Instance Attribute Details
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/proxy.rb', line 8 def timeout @timeout end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
7 8 9 |
# File 'lib/proxy.rb', line 7 def type @type end |
Instance Method Details
#change_ip ⇒ Object
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_ip ⇒ Object
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 |
#url ⇒ Object
19 20 21 |
# File 'lib/proxy.rb', line 19 def url return @host.to_s+":"+@port.to_s end |