Class | Net::SSH::Proxy::SOCKS4 |
In: |
lib/net/ssh/proxy/socks4.rb
|
Parent: | Object |
An implementation of a socket factory that returns a socket which will tunnel the connection through a SOCKS4 proxy. It allows explicit specification of the user, but if it is not given it will look in the SOCKS_USER and CONNECT_USER environment variables as well.
SOCKS_VERSION | = | 4 |
SOCKS_CMD_CONNECT | = | 1 |
SOCKS_GRANTED | = | 90 |
SOCKS_REJECTED | = | 91 |
SOCKS_IDENTD_REJECT | = | 92 |
SOCKS_IDENTD_BAD | = | 93 |
Create a new proxy connection to the given proxy host and port. Optionally, a @:user@ option may be given to identify the username with which to authenticate.
# File lib/net/ssh/proxy/socks4.rb, line 44 44: def initialize( proxy_host, proxy_port=1080, options={} ) 45: @proxy_host = proxy_host 46: @proxy_port = proxy_port 47: @options = options 48: end
Return a new socket connected to the given host and port via the proxy that was requested when the socket factory was instantiated.
# File lib/net/ssh/proxy/socks4.rb, line 52 52: def open( host, port ) 53: sock = TCPSocket.new( @proxy_host, @proxy_port ) 54: 55: ip_addr = IPAddr.new( Resolv.getaddress( host ) ) 56: 57: packet = [ SOCKS_VERSION, SOCKS_CMD_CONNECT, 58: port.to_i, ip_addr.to_i, 59: proxy_user, 0 ].pack( "CCnNA*C" ) 60: sock.send packet, 0 61: 62: version, status, port, ip = sock.recv( 8 ).unpack( "CCnN" ) 63: if status != SOCKS_GRANTED 64: sock.close 65: raise ConnectError, "error connecting to proxy (#{status})" 66: end 67: 68: return sock 69: end