Created
August 27, 2009 05:54
-
-
Save udzura/176112 to your computer and use it in GitHub Desktop.
./simple_pf.rb {FORWARD-TO-HOSTNAME}
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
#!/usr/bin/ruby | |
exit 1 if ARGV.empty? | |
require 'rubygems' | |
require 'net/ssh' | |
require 'yaml' | |
Login = YAML.load_file("./login.yml") | |
def start_forwarding | |
Net::SSH.start('localhost', Login[:user], :password => Login[:pass]) do |ssh| | |
puts "Start forwarding localhost:8080 to #{ARGV[0]}" | |
forwarding = true | |
ssh.forward.local("192.168.0.1", 8080, ARGV[0], 80) | |
Signal.trap(:INT) do | |
forwarding = false | |
end | |
ssh.loop(0.1) do | |
if forwarding | |
true | |
else | |
ssh.forward.cancel_local(8080, "192.168.0.1") | |
puts "Canceled" | |
false | |
end | |
end | |
end | |
end | |
start_forwarding |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment