public static void SetProxy(string ip_port)
{
/
/
打开注册表
RegistryKey regKey
=
Registry.CurrentUser;
string SubKeyPath
=
@
"Software\Microsoft\Windows\CurrentVersion\Internet Settings"
;
RegistryKey? optionKey
=
regKey.OpenSubKey(SubKeyPath, true);
/
/
更改健值,设置代理,
optionKey?.SetValue(
"ProxyEnable"
,
1
);
if
(ip_port.Length
=
=
0
)
{
optionKey?.SetValue(
"ProxyEnable"
,
0
);
}
optionKey?.SetValue(
"ProxyServer"
,
"socks5://"
+
ip_port);
optionKey?.SetValue(
"ProxyOverride"
,
"localhost;127.0.0.*;<local>"
);
/
/
Configure the WebRequest to use the SOCKS5 proxy
WebRequest.DefaultWebProxy
=
new WebProxy(
"socks5://"
+
ip_port, true, null);
/
/
激活代理设置
InternetSetOption(
0
,
39
, IntPtr.Zero,
0
);
InternetSetOption(
0
,
37
, IntPtr.Zero,
0
);
}