class TheMask::ProxyList::Proxy

Constants

HTTP_PROXY
SOCKS_PROXY
SUPPORTED_SOCKS_VERSIONS

Attributes

ip[RW]
password[RW]
port[RW]
socks_version[RW]
type[RW]
username[RW]

Public Class Methods

new(input_string = '') click to toggle source
# File lib/the_mask/proxy_list.rb, line 9
def initialize(input_string = '')
  unless input_string.empty?
    # Proxy string format = ip:port:username:password
    split_str = input_string.split(':')
    last_element = split_str[-1].to_s.downcase

    # Check if proxy has SOCKS parameter enabled, by default a proxy will always be a HTTP/s proxy
    if last_element.eql?(SOCKS_PROXY.to_s) && (split_str.length == 3 || split_str.length == 5)
      @type = SOCKS_PROXY
      socks_version = last_element[-1]
      if SUPPORTED_SOCKS_VERSIONS.include?(socks_version)
        @socks_version = socks_version.to_i
      else
        # Default version is the latest SOCKS, in this case ver. 5s
        @socks_version = SUPPORTED_SOCKS_VERSIONS[-1].to_i
      end
    else
      @type = HTTP_PROXY
    end
    @ip = split_str[0].to_s
    @port = split_str[1].to_i
    @username = split_str[2].to_s unless split_str[2].nil?
    @password = split_str[3].to_s unless split_str[3].nil?
  else
    @ip = nil
    @port = 0
    @username = nil
    @password = nil
  end
end

Public Instance Methods

is_HTTP?() click to toggle source
# File lib/the_mask/proxy_list.rb, line 44
def is_HTTP?
  @type == HTTP_PROXY
end
is_SOCKS?() click to toggle source
# File lib/the_mask/proxy_list.rb, line 40
def is_SOCKS?
  @type == SOCKS_PROXY
end