class Net::SSH::Proxy::SOCKS4
end
…
Net::SSH.start(‘host’, ‘user’, :proxy => proxy) do |ssh|
proxy = Net::SSH::Proxy::SOCKS4.new(‘proxy.host’, proxy_port, :user => ‘user’)
require ‘net/ssh/proxy/socks4’
pass the instantiated object via the :proxy key to Net::SSH.start:
An implementation of a SOCKS4 proxy. To use it, instantiate it, then
def initialize(proxy_host, proxy_port = 1080, options = {})
Optionally, a :user key may be given to identify the username
Create a new proxy connection to the given proxy host and port.
def initialize(proxy_host, proxy_port = 1080, options = {}) @proxy_host = proxy_host @proxy_port = proxy_port @options = options end
def open(host, port, connection_options)
Return a new socket connected to the given host and port via the
def open(host, port, connection_options) socket = Socket.tcp(proxy_host, proxy_port, nil, nil, connect_timeout: connection_options[:timeout]) ip_addr = IPAddr.new(Resolv.getaddress(host)) packet = [VERSION, CONNECT, port.to_i, ip_addr.to_i, options[:user]].pack("CCnNZ*") socket.send packet, 0 version, status, port, ip = socket.recv(8).unpack("CCnN") if status != GRANTED socket.close raise ConnectError, "error connecting to proxy (#{status})" end return socket end