Skip to content

Instantly share code, notes, and snippets.

@draftcode
Created July 15, 2013 14:41
Show Gist options
  • Select an option

  • Save draftcode/6000484 to your computer and use it in GitHub Desktop.

Select an option

Save draftcode/6000484 to your computer and use it in GitHub Desktop.
require 'net/ssh'
require 'tmpdir'
require 'socket'
path = Dir::Tmpname::create('forwarded_socket') { |path| path }
UNIXServer.open(path) do |server|
at_exit do
File.unlink(path)
end
Net::SSH.start('10.0.1.201', 'draftcode') do |ssh|
ssh.forward.local(server, '127.0.0.1', 1234)
Thread.fork { ssh.loop { true } }
loop do
p ssh.forward.active_locals
sleep 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment