10
11
12
13
14
15
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
|
# File 'lib/sockit/connection.rb', line 10
def connect(socket, host, port)
log(:yellow, "Connecting to SOCKS v#{config.version} server #{config.host}:#{config.port}")
if host !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/
host = Resolv::DNS.new.getaddress(host).to_s
end
data = case config.version.to_i
when 4 then
build_v4_connection_request(host, port)
when 5 then
build_v5_connection_request(host, port)
end
data = data.flatten.join
log(:yellow, "Requesting SOCKS v#{config.version} connection to #{host}:#{port}")
dump(:write, data)
socket.write(data)
log(:yellow, "Waiting for SOCKS v#{config.version} connection reply")
host, port = case config.version.to_i
when 4 then
process_v4_connection_response(socket)
when 5 then
process_v5_connection_response(socket)
end
log(:green, [host, port].inspect)
log(:green, "Connected to #{host}:#{port} via SOCKS v#{config.version} server #{config.host}:#{config.port}")
end
|