Created
March 23, 2012 05:42
-
-
Save cantremember/2167326 to your computer and use it in GitHub Desktop.
Net::SSH 'dumb forward' mode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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