Class: Ronin::Network::HTTP::Proxy
- Hash
- Ronin::Network::HTTP::Proxy
Constants
- DEFAULT_PORT
- 8080
Constructor Summary
Creates a new Proxy object that represents a proxy to connect to.
45 46 47 48 49 50 51 52 |
# File 'lib/ronin/network/http/proxy.rb', line 45 def initialize(={}) super() self[:host] = [:host] self[:port] = ([:port] || DEFAULT_PORT) self[:user] = [:user] self[:password] = [:password] end |
Public Visibility
Public Instance Method Summary
| #disable! |
Disables the Proxy object. |
|---|---|
| #enabled? |
Specifies whether the proxy object is usable. Returns: Boolean |
| #host |
Returns: String |
| #host=(new_host) |
Set the host-name of the proxy. Returns: String |
| #inspect |
Inspects the proxy object. Returns: String |
| #lag |
Measures the lag of the proxy. Returns: Float |
| #password |
Returns: String |
| #password=(new_password) |
Set the password to authenticate with for the proxy. Returns: Integer |
| #port |
Returns: Integer |
| #port=(new_port) |
Set the port of the proxy. Returns: Integer |
| #to_s |
Converts the proxy object to a String. Returns: String |
| #url |
Builds a HTTP URI from the proxy information. Returns: URI::HTTP |
| #user |
Returns: String |
| #user=(new_user) |
Set the user-name to authenticate as with the proxy. Returns: Integer |
| #valid? |
Tests the proxy. Returns: Boolean |
Public Class Method Details
parse
Parses a proxy URL.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ronin/network/http/proxy.rb', line 72 def Proxy.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 Proxy.new( :host => host, :port => port, :user => user, :password => password ) end |
Public Instance Method Details
disable!
Disables the Proxy object.
140 141 142 143 144 145 146 147 |
# File 'lib/ronin/network/http/proxy.rb', line 140 def disable! self[:host] = nil self[:port] = DEFAULT_PORT self[:user] = nil self[:password] = nil return self end |
enabled?
Specifies whether the proxy object is usable.
156 157 158 |
# File 'lib/ronin/network/http/proxy.rb', line 156 def enabled? !(self[:host].nil? || self[:port].nil?) end |
host
164 165 166 |
# File 'lib/ronin/network/http/proxy.rb', line 164 def host self[:host] end |
host=
Set the host-name of the proxy.
177 178 179 |
# File 'lib/ronin/network/http/proxy.rb', line 177 def host=(new_host) self[:host] = new_host.to_s end |
inspect
Inspects the proxy object.
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/ronin/network/http/proxy.rb', line 285 def inspect unless (self[:host] || self[:port]) str = 'disabled' else str = "#{self[:host]}:#{self[:port]}" if self[:user] auth_str = self[:user] if self[:password] auth_str = "#{auth_str}:#{self[:password]}" end str = "#{auth_str}@#{str}" end end return "#<#{self.class}: #{str}>" end |
lag
Measures the lag of the proxy.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/ronin/network/http/proxy.rb', line 118 def lag 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 |
password
227 228 229 |
# File 'lib/ronin/network/http/proxy.rb', line 227 def password self[:password] end |
password=
Set the password to authenticate with for the proxy.
240 241 242 |
# File 'lib/ronin/network/http/proxy.rb', line 240 def password=(new_password) self[:password] = new_password.to_s end |
port
185 186 187 |
# File 'lib/ronin/network/http/proxy.rb', line 185 def port self[:port] end |
port=
Set the port of the proxy.
198 199 200 |
# File 'lib/ronin/network/http/proxy.rb', line 198 def port=(new_port) self[:port] = new_port.to_i end |
to_s
Converts the proxy object to a String.
275 276 277 |
# File 'lib/ronin/network/http/proxy.rb', line 275 def to_s self[:host].to_s end |
url
Builds a HTTP URI from the proxy information.
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/ronin/network/http/proxy.rb', line 251 def url return nil unless enabled? userinfo = if self[:user] if self[:password] "#{self[:user]}:#{self[:password]}" else self[:user] end end return URI::HTTP.build({ :userinfo => userinfo, :host => self[:host], :port => self[:port] }) end |
user
206 207 208 |
# File 'lib/ronin/network/http/proxy.rb', line 206 def user self[:user] end |
user=
Set the user-name to authenticate as with the proxy.
219 220 221 |
# File 'lib/ronin/network/http/proxy.rb', line 219 def user=(new_user) self[:user] = new_user.to_s end |
valid?
Tests the proxy.
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/ronin/network/http/proxy.rb', line 100 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 |