Created
December 30, 2015 05:14
-
-
Save mlsteele/a3d8bc765fa573839f80 to your computer and use it in GitHub Desktop.
xorp: A wrapper for ssh reverse tunneling.
This file contains 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/env python | |
""" | |
Create a reverse proxy tunnel from a remote host back to localhost. | |
Useful for sharing local services with people who can only access the remote host. | |
You may need to add the line | |
GatewayPorts yes | |
to the /etc/ssh/sshd_config of the remote. | |
And then restart the ssh service (sudo service ssh restart). | |
Usage: | |
xorp <local_port> <remote_host> <remote_port> [--ssh-port=<port>] | |
xorp --help | |
Example: | |
$ xorp 80 milessteele.com 9050 | |
creating tunnel milessteele.com:9000 -> localhost:80 | |
... | |
tunnel destroyed | |
""" | |
import subprocess | |
from docopt import docopt | |
arguments = docopt(__doc__, version='Naval Fate 2.0') | |
local_port = arguments['<local_port>'] | |
remote_host = arguments['<remote_host>'] | |
remote_port = arguments['<remote_port>'] | |
ssh_port = arguments['--ssh-port'] or 22 | |
print "xorp creating tunnel {}:{} -> localhost:{}".format(remote_host, remote_port, local_port) | |
try: | |
subprocess.call(['ssh', '-N', '-p {}'.format(ssh_port), | |
'-R {}:localhost:{}'.format(remote_port, local_port), remote_host]) | |
except KeyboardInterrupt: | |
print "tunnel destroyed" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment