Tunnel prevent message when Ctrl+C

This commit is contained in:
Geoffrey Frogeye 2016-02-25 17:17:03 +01:00
parent 758576532b
commit 0e96c7c615

View file

@ -1,29 +1,32 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import sys try:
import os import sys
from subprocess import call import os
from subprocess import call
host, port = sys.argv[1:3] host, port = sys.argv[1:3]
proxy = os.environ.get('HTTP_PROXY') proxy = os.environ.get('HTTP_PROXY')
if proxy: if proxy:
proxy = proxy.strip('/') proxy = proxy.strip('/')
if proxy[:7] == 'http://': if proxy[:7] == 'http://':
proxy = proxy[7:] proxy = proxy[7:]
elif proxy[:8] == 'https://': elif proxy[:8] == 'https://':
proxy = proxy[8:] proxy = proxy[8:]
s = proxy.split('@') s = proxy.split('@')
user = None user = None
if len(s) == 2: if len(s) == 2:
user, proxy = s user, proxy = s
args = ['proxytunnel', '-p', proxy, '-d', host + ':' + port] args = ['proxytunnel', '-p', proxy, '-d', host + ':' + port]
if user: if user:
args += ['-P', user] args += ['-P', user]
call(args) call(args)
else: else:
call(['nc', host, port]) call(['nc', host, port])
except KeyboardInterrupt:
pass
# #!/usr/bin/env bash # #!/usr/bin/env bash