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,22 +36,34 @@ 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 i = 0
) while True:
try:
user = EnumKey(HKEY_USERS, i)
i += 1
except:
break
if user.endswith('_classes'):
continue
try: try:
key = '{}\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Internet Settings'.format(user)
aKey = OpenKey(HKEY_USERS, key, 0, KEY_QUERY_VALUE)
value = QueryValueEx(aKey, 'ProxyServer')[0] value = QueryValueEx(aKey, 'ProxyServer')[0]
if value: if value:
for p in parse_win_proxy(value): for p in parse_win_proxy(value):
if p not in duplicates:
yield p yield p
duplicates.add(p)
except Exception: except Exception:
pass pass
@ -59,22 +71,6 @@ def get_win_proxies():
finally: finally:
CloseKey(aKey) CloseKey(aKey)
aKey = OpenKey(
HKEY_LOCAL_MACHINE, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings',
0, KEY_QUERY_VALUE
)
try:
value=QueryValueEx(aKey,'ProxyServer')[0]
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