Skip to content

Instantly share code, notes, and snippets.

@udzura
Created August 27, 2009 05:54
Show Gist options
  • Save udzura/176112 to your computer and use it in GitHub Desktop.
Save udzura/176112 to your computer and use it in GitHub Desktop.
./simple_pf.rb {FORWARD-TO-HOSTNAME}
#!/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