Tunnel back in bash

This commit is contained in:
Geoffrey Frogeye 2016-11-20 14:34:48 +01:00
parent 42273239e7
commit 28d6cfa0ea
1 changed files with 17 additions and 39 deletions

View File

@ -1,41 +1,19 @@
#!/usr/bin/env python
#!/usr/bin/env bash
host="$1"
port="$2"
if [ -z "$http_proxy" ]; then
nc "$host" "$port"
else
proxy=$(echo http_proxy | sed 's/^https\?:\/\///' | sed 's/\/$//')
port=443 # Most won't want this
echo "$proxy" | grep '@'
if [ $? == 0 ]; then
user=$(echo $proxy | cut -d '@' -f 2)
proxy=$(echo $proxy | cut -d '@' -f 1)
proxytunnel -p $proxy -P $user -d $host:$port
else
proxytunnel -p $proxy -d $host:$port
fi
fi
try:
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])
except KeyboardInterrupt:
pass
# #!/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