import
_winreg as winreg
import
binascii
import
ctypes
import
time
proxy_server_addr
=
'127.0.0.1:8080'
auto_config_url
=
''
auto_config_mode
=
1
INTERNET_SETTINGS
=
winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r
'Software\Microsoft\Windows\CurrentVersion\Internet Settings'
,
0
, winreg.KEY_ALL_ACCESS)
Connections
=
winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r
'Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections'
,
0
, winreg.KEY_ALL_ACCESS)
def
set_key(key, subkey, value):
_, reg_type
=
winreg.QueryValueEx(key, subkey)
winreg.SetValueEx(key, subkey,
0
, reg_type, value)
(value , regtype)
=
winreg.QueryValueEx(Connections,
"DefaultConnectionSettings"
)
def
auto_config_Enable():
auto_config
=
binascii.b2a_hex(value)
auto_config
=
auto_config[:
16
]
+
'09'
+
auto_config[
18
:]
auto_config
=
binascii.a2b_hex(auto_config)
set_key(Connections,
'DefaultConnectionSettings'
, auto_config)
def
auto_config_Disable():
auto_config
=
binascii.b2a_hex(value)
auto_config
=
auto_config[:
16
]
+
'01'
+
auto_config[
18
:]
auto_config
=
binascii.a2b_hex(auto_config)
set_key(Connections,
'DefaultConnectionSettings'
, auto_config)
proxy_status
=
winreg.QueryValueEx(INTERNET_SETTINGS,
'ProxyEnable'
)
proxy_flag
=
proxy_status[
0
]
def
Proxy_Enable():
set_key(INTERNET_SETTINGS,
'ProxyEnable'
,
1
)
set_key(INTERNET_SETTINGS,
'ProxyServer'
, proxy_server_addr)
def
Proxy_Disable():
set_key(INTERNET_SETTINGS,
'ProxyEnable'
,
0
)
def
refresh():
INTERNET_OPTION_REFRESH
=
37
INTERNET_OPTION_SETTINGS_CHANGED
=
39
internet_set_option
=
ctypes.windll.Wininet.InternetSetOptionW
internet_set_option(
0
, INTERNET_OPTION_REFRESH,
0
,
0
)
internet_set_option(
0
, INTERNET_OPTION_SETTINGS_CHANGED,
0
,
0
)
winreg.SetValueEx(INTERNET_SETTINGS,
'AutoConfigURL'
,
0
,
1
,auto_config_url)
if
proxy_flag
=
=
0
:
Proxy_Enable()
auto_config_Disable()
winreg.SetValueEx(INTERNET_SETTINGS,
'AutoConfigURL'
,
0
,
1
,'')
print
"Proxy_Enable"
if
proxy_flag
=
=
1
:
Proxy_Disable()
winreg.SetValueEx(INTERNET_SETTINGS,
'AutoConfigURL'
,
0
,
1
,auto_config_url)
print
"Proxy_Disable"
refresh()