Skip to content

Instantly share code, notes, and snippets.

@itszero
Forked from anonymous/port_forwarding.rb
Created August 13, 2010 15:38
Show Gist options
  • Save itszero/523069 to your computer and use it in GitHub Desktop.
Save itszero/523069 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby -w
require 'socket'
server = TCPServer.open(7788)
loop do
Thread.start(server.accept) do |client|
client.write "[Host]:[Port]> "
target = ""
while s = client.getc.chr
client.write s
break if s == "\n" || s == "\r"
target += s
end
target = target.split(":")
client.write "Connecting to #{target.inspect}...\n"
remote = TCPSocket.open(target[0], target[1] || 23)
loop do
r, w, e = IO.select([client, remote], nil, nil, 0)
(r || []).each do |f|
if f == remote
client.write remote.getc.chr
else
remote.write client.getc.chr
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment