Class: Ronin::Network::HTTP::Proxy

  • Hash
    • Ronin::Network::HTTP::Proxy

Constants

DEFAULT_PORT
8080

Constructor Summary

public initialize(options = {})

Creates a new Proxy object that represents a proxy to connect to.

Meta Tags

Parameters:

Options Hash options
Key Name Default Value Accepted Types Description
:host N/A [String]

The host-name of the proxy.

:port DEFAULT_PORT [Integer]

The port that the proxy is running on.

:user N/A [String]

The user-name to authenticate as.

:password N/A [String]

The password to authenticate with.

[View source]


45
46
47
48
49
50
51
52
# File 'lib/ronin/network/http/proxy.rb', line 45

def initialize(options={})
  super()

  self[:host] = options[:host]
  self[:port] = (options[:port] || DEFAULT_PORT)
  self[:user] = options[:user]
  self[:password] = options[:password]
end

Public Visibility

Public Class Method Summary

parse(proxy)

Parses a proxy URL.

Returns: Proxy

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

public Proxy parse(proxy)

Parses a proxy URL.

Meta Tags

Examples

  Proxy.parse('217.31.51.77:443')
  Proxy.parse('joe:lol@127.0.0.1:8080')
  Proxy.parse('http://201.26.192.61:8080')

Parameters:

[String, URI::HTTP] proxy

The proxy URL in String form.

Returns:

[Proxy]

The parsed proxy information.

[View source]


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!

public disable!

Disables the Proxy object.

[View source]


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?

public Boolean enabled?

Specifies whether the proxy object is usable.

Meta Tags

Returns:

[Boolean]

Specifies whether the proxy object is usable by Net::HTTP::Proxy.

[View source]


156
157
158
# File 'lib/ronin/network/http/proxy.rb', line 156

def enabled?
  !(self[:host].nil? || self[:port].nil?)
end

host

public String host

Meta Tags

Returns:

[String, nil]

The host-name to connect when using the proxy.

[View source]


164
165
166
# File 'lib/ronin/network/http/proxy.rb', line 164

def host
  self[:host]
end

host=

public String host=(new_host)

Set the host-name of the proxy.

Meta Tags

Parameters:

[String] new_host

The new host-name to use.

Returns:

[String]

The new host-name to use.

[View source]


177
178
179
# File 'lib/ronin/network/http/proxy.rb', line 177

def host=(new_host)
  self[:host] = new_host.to_s
end

inspect

public String inspect

Inspects the proxy object.

Meta Tags

Returns:

[String]

The inspection of the proxy object.

[View source]


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

public Float lag

Measures the lag of the proxy.

Meta Tags

Returns:

[Float]

The extra number of seconds it takes the proxy to process the request.

[View source]


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

public String password

Meta Tags

Returns:

[String, nil]

The password to authenticate with, when using the proxy.

[View source]


227
228
229
# File 'lib/ronin/network/http/proxy.rb', line 227

def password
  self[:password]
end

password=

public Integer password=(new_password)

Set the password to authenticate with for the proxy.

Meta Tags

Returns:

[Integer]

The new user-name to use.

[View source]


240
241
242
# File 'lib/ronin/network/http/proxy.rb', line 240

def password=(new_password)
  self[:password] = new_password.to_s
end

port

public Integer port

Meta Tags

Returns:

[Integer]

The port to connect when using the proxy.

[View source]


185
186
187
# File 'lib/ronin/network/http/proxy.rb', line 185

def port
  self[:port]
end

port=

public Integer port=(new_port)

Set the port of the proxy.

Meta Tags

Parameters:

[Integer] new_port

The new port to use.

Returns:

[Integer]

The new port to use.

[View source]


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

public String to_s

Converts the proxy object to a String.

Meta Tags

Returns:

[String]

The host-name of the proxy.

[View source]


275
276
277
# File 'lib/ronin/network/http/proxy.rb', line 275

def to_s
  self[:host].to_s
end

url

public URI::HTTP url

Builds a HTTP URI from the proxy information.

Meta Tags

Returns:

[URI::HTTP, nil]

The HTTP URI representing the proxy. If the proxy is disabled, then nil will be returned.

[View source]


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

public String user

Meta Tags

Returns:

[String, nil]

The user-name to authenticate as, when using the proxy.

[View source]


206
207
208
# File 'lib/ronin/network/http/proxy.rb', line 206

def user
  self[:user]
end

user=

public Integer user=(new_user)

Set the user-name to authenticate as with the proxy.

Meta Tags

Parameters:

[String] new_user

The new user-name to use.

Returns:

[Integer]

The new user-name to use.

[View source]


219
220
221
# File 'lib/ronin/network/http/proxy.rb', line 219

def user=(new_user)
  self[:user] = new_user.to_s
end

valid?

public Boolean valid?

Tests the proxy.

Meta Tags

Returns:

[Boolean]

Specifies if the proxy can proxy requests.

[View source]


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
Generated on Friday, September 25 2009 at 02:57:45 PM by YARD 0.2.3.5 (ruby-1.8.6).