SSH auto tunnel

This commit is contained in:
Geoffrey Frogeye 2016-02-19 13:46:26 +01:00
parent e42d69e348
commit 174034a7fb
2 changed files with 41 additions and 4 deletions

View file

@ -42,10 +42,10 @@ function proxy_off {
unset https_proxy
unset ftp_proxy
unset rsync_proxy
export HTTP_PROXY
export HTTPS_PROXY
export FTP_PROXY
export RSYNC_PROXY
unset HTTP_PROXY
unset HTTPS_PROXY
unset FTP_PROXY
unset RSYNC_PROXY
echo -e "Proxy removed"
}

37
scripts/tunnel Executable file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python3
import sys
import os
from subprocess import call
host, port = sys.argv[1:3]
proxy = os.environ.get('HTTP_PROXY')
if proxy:
proxy = proxy.strip('/')
if proxy[:7] == 'http://':
proxy = proxy[7:]
elif proxy[:8] == 'https://':
proxy = proxy[8:]
s = proxy.split('@')
user = None
if len(s) == 2:
user, proxy = s
args = ['proxytunnel', '-p', proxy, '-d', host + ':' + port]
if user:
args += ['-P', user]
call(args)
else:
call(['nc', host, port])
# #!/usr/bin/env bash
# host="$1"
# port="$2"
#
# if [ -z $HTTP_PROXY ]; then
# nc "$host" "$port"
# else
# proxytunnel -p "$HTTP_PROXY" -d "$host:$port"
# fi