Module: Rex::Socket::Proxies
- Defined in:
- lib/rex/socket/proxies.rb
Defined Under Namespace
Modules: ProxyType
Class Method Summary collapse
-
.parse(value) ⇒ Array<URI>
The array of proxies.
- .supported_types ⇒ Object
Class Method Details
.parse(value) ⇒ Array<URI>
Returns The array of proxies.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rex/socket/proxies.rb', line 16 def self.parse(value) proxies = [] value.to_s.strip.split(',').each do |proxy| proxy = proxy.strip # replace the first : with :// so it can be parsed as a URI # URIs will offer more flexibility long term, but we'll keep backwards compatibility for now by treating : as :// proxy = proxy.sub(/\A(\w+):(\w+)/, '\1://\2') uri = URI(proxy) unless supported_types.include?(uri.scheme) raise Rex::RuntimeError.new("Unsupported proxy scheme: #{uri.scheme}") end if uri.host.nil? || uri.host.empty? raise Rex::RuntimeError.new("A proxy URI must include a valid host.") end if uri.port.nil? && uri.scheme.start_with?('socks') uri.port = 1080 end if uri.port.nil? || uri.port.zero? raise Rex::RuntimeError.new("A proxy URI must include a valid port.") end proxies << uri end proxies end |
.supported_types ⇒ Object
48 49 50 |
# File 'lib/rex/socket/proxies.rb', line 48 def self.supported_types ProxyType.constants.map { |c| ProxyType.const_get(c) } end |