我正在制作SSH隧道应用程序,并且需要能够自动强制系统使用HTTP& Socks5代理,并使更改立即生效。 HTTP代理现在由PoshHTTP class完美地处理,但我无法弄清楚如何对SOCKS5做同样的事情。
我已经尝试过强制注册表中的更改,但它们不会立即生效,而且它不可靠。在大多数情况下,我必须打开互联网选项>在设置生效之前的局域网设置,因此用户也可以在此时手动设置代理。
有没有办法做到这一点,我错过了?如果我可以修改poshHTTP来做这件事会很棒,但我没有太大的希望。
我愿意支付50美元购买可行的c#解决方案,该解决方案立即生效(仅通过PayPal支付)
答案 0 :(得分:1)
任何人来到这里都想知道Tor,这可能对你有用
public struct Struct_INTERNET_PROXY_INFO
{
public int dwAccessType;
public IntPtr proxy;
public IntPtr proxyBypass;
};
[DllImport("wininet.dll", SetLastError = true)]
public static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
public static void RefreshProxy()
{
try
{
//RESTART TOR
Struct_INTERNET_PROXY_INFO struct_IPI;
struct_IPI.dwAccessType = 3;
struct_IPI.proxy = Marshal.StringToHGlobalAnsi("socks=127.0.0.1:9050");
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");
IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));
Marshal.StructureToPtr(struct_IPI, intptrStruct, true);
InternetSetOption(IntPtr.Zero, 38, intptrStruct, Marshal.SizeOf(struct_IPI));
}
catch (Exception){ }
}
答案 1 :(得分:0)
在另一个论坛上寻求帮助后找到解决方案。 最后我能够继续使用我在其他地方使用的PoshHTTP类,而不是只传递ip:port就像这样使用它
PoshHttp.Proxies.SetProxy("socks=socks://$ip:$port");