dotfiles/scripts/tunnel

42 lines
832 B
Plaintext
Raw Normal View History

#!/usr/bin/env python
2016-02-19 13:46:26 +01:00
2016-02-25 17:17:03 +01:00
try:
import sys
import os
from subprocess import call
2016-02-19 13:46:26 +01:00
2016-02-25 17:17:03 +01:00
host, port = sys.argv[1:3]
proxy = os.environ.get('HTTP_PROXY')
2016-02-19 13:46:26 +01:00
2016-02-25 17:17:03 +01:00
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)
2016-02-19 13:46:26 +01:00
2016-02-25 17:17:03 +01:00
else:
call(['nc', host, port])
except KeyboardInterrupt:
pass
2016-02-19 13:46:26 +01:00
# #!/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