-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
nc-negotiate
37 lines (30 loc) · 1.37 KB
/
nc-negotiate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python
import argparse
import os
try:
from urlparse import urlparse
except ImportError:
from urllib.parse import urlparse
from proxy_negotiate import netcat, __version__
def proxy_host_from_env():
if 'HTTPS_PROXY' in os.environ:
return urlparse(os.environ['HTTPS_PROXY']).hostname
elif 'HTTP_PROXY' in os.environ:
return urlparse(os.environ['HTTP_PROXY']).hostname
else:
raise RuntimeError('No PROXY environment variable set.')
def proxy_port_from_env():
if 'HTTPS_PROXY' in os.environ:
return urlparse(os.environ['HTTPS_PROXY']).port
elif 'HTTP_PROXY' in os.environ:
return urlparse(os.environ['HTTP_PROXY']).port
else:
raise RuntimeError('No PROXY environment variable set.')
parser = argparse.ArgumentParser(description='')
parser.add_argument('host', help='Hostname or IP to tunnel a connection to.')
parser.add_argument('port', help='Port to tunnel a connection to', type=int)
parser.add_argument('proxy_host', help='Hostname of the proxy server.', nargs='?', default=proxy_host_from_env())
parser.add_argument('proxy_port', help='Port of the proxy server.', nargs='?', type=int, default=proxy_port_from_env())
parser.add_argument('--version', '-V', action='version', version='%(prog)s ' + __version__)
args = parser.parse_args()
netcat(args.host, args.port, args.proxy_host, args.proxy_port)