Try to retrieve proxies from all users

This commit is contained in:
Oleksii Shevchuk 2017-04-27 17:19:14 +03:00
parent 60ff7ccea5
commit 798f266f22
1 changed files with 25 additions and 29 deletions

View File

@ -36,45 +36,41 @@ def parse_win_proxy(val):
return l return l
def get_win_proxies(): def get_win_proxies():
#TODO retrieve all users proxy settings, not only HKCU
try: try:
from _winreg import OpenKey, CloseKey, QueryValueEx, HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER, KEY_QUERY_VALUE from _winreg import EnumKey, OpenKey, CloseKey, QueryValueEx
from _winreg import HKEY_LOCAL_MACHINE, HKEY_USERS, KEY_QUERY_VALUE
except: except:
return return
aKey = OpenKey( duplicates = set()
HKEY_CURRENT_USER, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
0, KEY_QUERY_VALUE
)
try: i = 0
value = QueryValueEx(aKey, 'ProxyServer')[0] while True:
if value: try:
for p in parse_win_proxy(value): user = EnumKey(HKEY_USERS, i)
yield p i += 1
except:
break
except Exception: if user.endswith('_classes'):
pass continue
finally: try:
CloseKey(aKey) key = '{}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'.format(user)
aKey = OpenKey(HKEY_USERS, key, 0, KEY_QUERY_VALUE)
value = QueryValueEx(aKey, 'ProxyServer')[0]
if value:
for p in parse_win_proxy(value):
if p not in duplicates:
yield p
duplicates.add(p)
aKey = OpenKey( except Exception:
HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings', pass
0, KEY_QUERY_VALUE
)
try: finally:
value=QueryValueEx(aKey,'ProxyServer')[0] CloseKey(aKey)
if value:
for p in parse_win_proxy(value):
yield p
except Exception:
pass
finally:
CloseKey(aKey)
def get_python_proxies(): def get_python_proxies():
global PROXY_MATCHER global PROXY_MATCHER