Class: Ronin::Network::HTTP::Proxy
- Defined in:
- lib/ronin/network/http/proxy.rb
Overview
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#user ⇒ Object
Returns the value of attribute user.
Class Method Summary collapse
-
.create(proxy) ⇒ Proxy
Creates a new proxy.
-
.parse(proxy) ⇒ Proxy
Parses a proxy URL.
Instance Method Summary collapse
-
#anonymous? ⇒ Boolean
Determines whether the proxy will hide our IP address.
-
#disable! ⇒ Object
Disables the Proxy object.
-
#enabled? ⇒ Boolean
Specifies whether the proxy object is usable.
-
#initialize(options = {}) ⇒ Proxy
constructor
Creates a new Proxy object that represents a proxy to connect to.
-
#inspect ⇒ String
Inspects the proxy object.
-
#latency ⇒ Float
(also: #lag)
Measures the latency of the proxy.
-
#proxied_ip ⇒ String
The IP address the proxy sends with proxied requests.
-
#to_s ⇒ String
Converts the proxy object to a String.
-
#transparent? ⇒ Boolean
Determines whether the proxy forwards our IP address.
-
#url ⇒ URI::HTTP?
Builds a HTTP URI from the proxy information.
-
#valid? ⇒ Boolean
Tests the proxy.
Constructor Details
#initialize(options = {}) ⇒ Proxy
Creates a new Proxy object that represents a proxy to connect to.
53 54 55 56 57 58 59 60 |
# File 'lib/ronin/network/http/proxy.rb', line 53 def initialize(={}) super( [:host], [:port], [:user], [:password] ) end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host
31 32 33 |
# File 'lib/ronin/network/http/proxy.rb', line 31 def host @host end |
#password ⇒ Object
Returns the value of attribute password
31 32 33 |
# File 'lib/ronin/network/http/proxy.rb', line 31 def password @password end |
#port ⇒ Object
Returns the value of attribute port
31 32 33 |
# File 'lib/ronin/network/http/proxy.rb', line 31 def port @port end |
#user ⇒ Object
Returns the value of attribute user
31 32 33 |
# File 'lib/ronin/network/http/proxy.rb', line 31 def user @user end |
Class Method Details
.create(proxy) ⇒ Proxy
Creates a new proxy.
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ronin/network/http/proxy.rb', line 119 def self.create(proxy) case proxy when Proxy proxy when URI::HTTP new( :host => proxy.host, :port => proxy.port, :user => proxy.user, :password => proxy.password ) when Hash new(proxy) when String parse(proxy) when nil new else raise(ArgumentError,"argument must be either a #{self}, URI::HTTP, Hash or String") end end |
.parse(proxy) ⇒ Proxy
Parses a proxy URL.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/ronin/network/http/proxy.rb', line 82 def self.parse(proxy) proxy = proxy.to_s.gsub(/^http(s)?:\/*/,'') if proxy.include?('@') auth, proxy = proxy.split('@',2) user, password = auth.split(':') else user = nil password = nil end host, port = proxy.split(':',2) port = port.to_i if port return new( :host => host, :port => port, :user => user, :password => password ) end |
Instance Method Details
#anonymous? ⇒ Boolean
Determines whether the proxy will hide our IP address.
225 226 227 |
# File 'lib/ronin/network/http/proxy.rb', line 225 def anonymous? !(transparent?) end |
#disable! ⇒ Object
Disables the Proxy object.
234 235 236 237 238 239 240 241 |
# File 'lib/ronin/network/http/proxy.rb', line 234 def disable! self.host = nil self.port = nil self.user = nil self.password = nil return self end |
#enabled? ⇒ Boolean
Specifies whether the proxy object is usable.
252 253 254 |
# File 'lib/ronin/network/http/proxy.rb', line 252 def enabled? !(host.nil?) end |
#inspect ⇒ String
Inspects the proxy object.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/ronin/network/http/proxy.rb', line 303 def inspect unless host str = 'disabled' else str = '' str << host.to_s str << ":#{port}" if port if user auth_str = '' auth_str << user.to_s if password auth_str << ":#{password}" end str = "#{auth_str}@#{str}" end end return "#<#{self.class}: #{str}>" end |
#latency ⇒ Float Also known as: lag
Measures the latency of the proxy.
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/ronin/network/http/proxy.rb', line 169 def latency time = lambda { |proxy| t1 = Time.now Net.http_head( :url => 'http://www.example.com/', :proxy => proxy ) t2 = Time.now (t2 - t1) } begin return (time.call(self) - time.call(nil)) rescue Timeout::Error, StandardError return (1.0/0) end end |
#proxied_ip ⇒ String
The IP address the proxy sends with proxied requests.
198 199 200 201 202 203 |
# File 'lib/ronin/network/http/proxy.rb', line 198 def proxied_ip IPAddr.extract(Net.http_get_body( :url => Network::IP_URL, :proxy => self )).first end |
#to_s ⇒ String
Converts the proxy object to a String.
291 292 293 |
# File 'lib/ronin/network/http/proxy.rb', line 291 def to_s host.to_s end |
#transparent? ⇒ Boolean
Determines whether the proxy forwards our IP address.
213 214 215 |
# File 'lib/ronin/network/http/proxy.rb', line 213 def transparent? Network.ip == proxied_ip end |
#url ⇒ URI::HTTP?
Builds a HTTP URI from the proxy information.
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'lib/ronin/network/http/proxy.rb', line 265 def url return nil unless enabled? userinfo = if user if password "#{user}:#{password}" else user end end return URI::HTTP.build( :userinfo => userinfo, :host => host, :port => port ) end |
#valid? ⇒ Boolean
Tests the proxy.
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ronin/network/http/proxy.rb', line 149 def valid? begin Net.http_get_body( :url => 'http://www.example.com/', :proxy => self ).include?('Example Web Page') rescue Timeout::Error, StandardError return false end end |