Skip to content

Instantly share code, notes, and snippets.

@cantremember
Created March 23, 2012 05:42
Show Gist options
  • Save cantremember/2167326 to your computer and use it in GitHub Desktop.
Save cantremember/2167326 to your computer and use it in GitHub Desktop.
Net::SSH 'dumb forward' mode
def ports, offset = [], 0
# ...
Net::SSH.start(hostname, user, :forward_agent => true, :verbose => :warn) do |ssh|
ports.each do |port|
ssh.forward.local port + offset, 'localhost', port
end
# loop, with an event loop every 0.1s, until Ctrl-C is pressed
puts "[Ctrl-C] to terminate..."
interrupted = false
trap('INT') { interrupted = true }
ssh.loop(0.1) {
not interrupted
}
ports.each do |port|
ssh.forward.cancel_local port + offset
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment