From 3bbdb497d261838ddf79de6180fbfd3b3107a5fa Mon Sep 17 00:00:00 2001 From: shellster <shellster@Tarsus.local> Date: Tue, 12 Apr 2016 15:48:58 -0700 Subject: [PATCH 1/2] Fixed autoproxy bug added getproxies() proxy detection --- pupy/network/launchers/auto_proxy.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pupy/network/launchers/auto_proxy.py b/pupy/network/launchers/auto_proxy.py index 3b30a801..f2ec7d5e 100644 --- a/pupy/network/launchers/auto_proxy.py +++ b/pupy/network/launchers/auto_proxy.py @@ -12,6 +12,8 @@ import os import socket import time import subprocess +import urllib + try: from urllib import request as urllib except ImportError: @@ -92,12 +94,29 @@ def get_proxies(wpad_timeout=600): except Exception: pass - + env_proxy=os.environ.get('HTTP_PROXY') if env_proxy: - user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$","http://proxy.domain.com:3128").groups() + user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$",env_proxy).groups() yield ('HTTP', proxy, user, passwd) + try: + python_proxies = urllib.getproxies() + except: + python_proxies = urllib.request.getproxies() + + if len(python_proxies) > 0: + for key in python_proxies: + if key.upper() in ('HTTP', 'HTTPS', 'SOCKS') and python_proxies[key] != '': + user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$",python_proxies[key]).groups() + + if key.upper() == 'SOCKS': + key = 'SOCKS4' + elif key.upper() == 'HTTPS': + key = 'HTTP' + + yield(key.upper(), proxy, user, passwd) + if last_wpad is None or time.time()-last_wpad > wpad_timeout: # to avoid flooding the network with wpad requests :) last_wpad=time.time() try: @@ -111,7 +130,6 @@ def get_proxies(wpad_timeout=600): pass - class AutoProxyLauncher(BaseLauncher): """ Automatically search a HTTP/SOCKS proxy on the system and use that proxy with the specified TCP transport. From df2ab667d8e6d955154334012ecf22883ead2ae0 Mon Sep 17 00:00:00 2001 From: shellster <shellster@Tarsus.local> Date: Tue, 12 Apr 2016 15:53:10 -0700 Subject: [PATCH 2/2] Cleaned-up code --- pupy/network/launchers/auto_proxy.py | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/pupy/network/launchers/auto_proxy.py b/pupy/network/launchers/auto_proxy.py index f2ec7d5e..a41a3851 100644 --- a/pupy/network/launchers/auto_proxy.py +++ b/pupy/network/launchers/auto_proxy.py @@ -100,22 +100,18 @@ def get_proxies(wpad_timeout=600): user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$",env_proxy).groups() yield ('HTTP', proxy, user, passwd) - try: - python_proxies = urllib.getproxies() - except: - python_proxies = urllib.request.getproxies() + python_proxies = urllib.getproxies() - if len(python_proxies) > 0: - for key in python_proxies: - if key.upper() in ('HTTP', 'HTTPS', 'SOCKS') and python_proxies[key] != '': - user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$",python_proxies[key]).groups() - - if key.upper() == 'SOCKS': - key = 'SOCKS4' - elif key.upper() == 'HTTPS': - key = 'HTTP' - - yield(key.upper(), proxy, user, passwd) + for key in python_proxies: + if key.upper() in ('HTTP', 'HTTPS', 'SOCKS') and python_proxies[key] != '': + user, passwd, proxy=re.match("^(?:https?://)?(?:(?P<user>\w+):?(?P<password>\w*)@)?(?P<proxy_addr>\S+:[0-9]+)$",python_proxies[key]).groups() + + if key.upper() == 'SOCKS': + key = 'SOCKS4' + elif key.upper() == 'HTTPS': + key = 'HTTP' + + yield(key.upper(), proxy, user, passwd) if last_wpad is None or time.time()-last_wpad > wpad_timeout: # to avoid flooding the network with wpad requests :) last_wpad=time.time()