An implementation of a SOCKS4 proxy. To use it, instantiate it, then pass the instantiated object via the :proxy key to Net::SSH.start:
require 'net/ssh/proxy/socks4' proxy = Net::SSH::Proxy::SOCKS4.new('proxy.host', proxy_port, :user => 'user') Net::SSH.start('host', 'user', :proxy => proxy) do |ssh| ... end
Constants
VERSION | = | 4 | The SOCKS protocol version used by this class | |
CONNECT | = | 1 | The packet type for connection requests | |
GRANTED | = | 90 | The status code for a successful connection |
Attributes
options | [R] | The additional options that were given to the proxy’s constructor. |
proxy_host | [R] | The proxy’s host name or IP address, as given to the constructor. |
proxy_port | [R] | The proxy’s port number. |
Public class methods
new
(proxy_host, proxy_port=1080, options={})
Create a new proxy connection to the given proxy host and port. Optionally, a :user key may be given to identify the username with which to authenticate.
[show source]
# File lib/net/ssh/proxy/socks4.rb, line 42 42: def initialize(proxy_host, proxy_port=1080, options={}) 43: @proxy_host = proxy_host 44: @proxy_port = proxy_port 45: @options = options 46: end
Public instance methods
open
(host, port)
Return a new socket connected to the given host and port via the proxy that was requested when the socket factory was instantiated.
[show source]
# File lib/net/ssh/proxy/socks4.rb, line 50 50: def open(host, port) 51: socket = TCPSocket.new(proxy_host, proxy_port) 52: ip_addr = IPAddr.new(Resolv.getaddress(host)) 53: 54: packet = [VERSION, CONNECT, port.to_i, ip_addr.to_i, options[:user]].pack("CCnNZ*") 55: socket.send packet, 0 56: 57: version, status, port, ip = socket.recv(8).unpack("CCnN") 58: if status != GRANTED 59: socket.close 60: raise ConnectError, "error connecting to proxy (#{status})" 61: end 62: 63: return socket 64: end