Parse socks_proxy arg with urllib.parse and support more parameters
This commit is contained in:
parent
7b62a7b14a
commit
f8e0eefb39
|
@ -5,8 +5,10 @@ import base64
|
|||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import re
|
||||
import signal
|
||||
import socket
|
||||
from urllib import parse
|
||||
|
||||
try:
|
||||
import socks
|
||||
|
@ -112,13 +114,14 @@ def parse_arguments(): # pylint: disable=too-many-branches,too-many-statements
|
|||
shared.i2p_sam_port = args.i2p_sam_port
|
||||
if args.i2p_transient:
|
||||
shared.i2p_transient = True
|
||||
if args.socks_proxy:
|
||||
addr = args.socks_proxy.split(':')
|
||||
shared.socks_proxy = (addr[0], int(addr[1]))
|
||||
if args.tor:
|
||||
shared.tor = True
|
||||
if not args.socks_proxy:
|
||||
shared.socks_proxy = ('127.0.0.1', 9050)
|
||||
args.socks_proxy = '127.0.0.1:9050'
|
||||
if args.socks_proxy:
|
||||
if not re.match(r'^.*://', args.socks_proxy):
|
||||
args.socks_proxy = '//' + args.socks_proxy
|
||||
shared.socks_proxy = parse.urlparse(args.socks_proxy, scheme='socks5')
|
||||
|
||||
|
||||
def bootstrap_from_dns():
|
||||
|
@ -265,14 +268,21 @@ def main():
|
|||
'Unfortunately you cannot use both I2P and SOCKS proxy.')
|
||||
return
|
||||
|
||||
try:
|
||||
proxy_type = socks.PROXY_TYPES[shared.socks_proxy.scheme.upper()]
|
||||
except KeyError:
|
||||
logging.error('Unsupported proxy schema!')
|
||||
return
|
||||
|
||||
# FIXME: the Connection() code would be too complex
|
||||
# without this monkeypatching
|
||||
def create_connection(
|
||||
dst_pair, timeout=None, source_address=None,
|
||||
proxy_type=socks.PROXY_TYPE_SOCKS5,
|
||||
proxy_addr=shared.socks_proxy[0],
|
||||
proxy_port=shared.socks_proxy[1], proxy_rdns=True,
|
||||
proxy_username=None, proxy_password=None,
|
||||
proxy_type=proxy_type,
|
||||
proxy_addr=shared.socks_proxy.hostname,
|
||||
proxy_port=shared.socks_proxy.port, proxy_rdns=True,
|
||||
proxy_username=shared.socks_proxy.username,
|
||||
proxy_password=shared.socks_proxy.password,
|
||||
socket_options=None
|
||||
):
|
||||
return socks.create_connection(
|
||||
|
|
Loading…
Reference in New Issue