Skip to content

Instantly share code, notes, and snippets.

@jfinstrom
Created May 20, 2014 20:33
Show Gist options
  • Save jfinstrom/23101efed5e6ccb25961 to your computer and use it in GitHub Desktop.
Save jfinstrom/23101efed5e6ccb25961 to your computer and use it in GitHub Desktop.
My script to tunnel web ports when I ssh...
#!/usr/bin/env python
import subprocess
import sys
import os
from argparse import ArgumentParser
shellcmd='xterm -e'
parser = ArgumentParser()
parser.add_argument('--port', action='store', help='SSH port default 22')
parser.add_argument('--username', action='store', help='default root')
parser.add_argument('--localport', action='store', help='Where you will poing yout browser: default http://localhost:9999')
parser.add_argument('--ssllocalport', action='store', help='Where you will poing yout browser: default http://localhost:9998')
parser.add_argument('--webport', action='store', help='where apache is listening on the remote server (http) default 80')
parser.add_argument('--sslwebport', action='store', help='where apache is listening on the remote server for ssl (https) default 443')
parser.add_argument('host', nargs='?', help='hostname or IP')
arg = parser.parse_args()
username = 'root'
extport = '22'
locport = '9999'
ssllocport = '9998'
webport = '80'
sslwebport = '443'
host = arg.host
if arg.port:
extport = arg.port
if arg.localport:
locport = arg.localport
if arg.ssllocalport:
ssllocport = arg.ssllocalport
if arg.webport:
webport = arg.webport
if arg.sslwebport:
sslwebport = arg.sslwebport
if arg.username:
username = arg.username
command = "ssh -L %s:localhost:%s -L %s:localhost:%s %s@%s -p %s" % (locport,webport,ssllocport,sslwebport,username,host,extport)
os.popen("%s '%s'" % (shellcmd,command))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment