我需要找到IE中的代理设置,以便设置RCUrl。但是IE中无法显示这些设置(医院管理员已将整个框“灰化”)。我了解到有一个功能可以显示IE的代理设置(WinHttpGetIEProxyConfigForCurrentUser)。由于我只熟悉R(统计学),在该语言中不存在此功能-获取此功能的输出最简单的方法是什么?它能在Excel中调用吗?
以下是不同的方法。从R中,使用system2来调用外部程序获取此信息。
param ($reqUrl)
$source = @"
public class WinHttp
{
[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct WinhttpCurrentUserIeProxyConfig
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.Bool)]
public bool AutoDetect;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string AutoConfigUrl;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string Proxy;
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
public string ProxyBypass;
}
[System.Runtime.InteropServices.DllImport("winhttp.dll", SetLastError = true)]
static extern bool WinHttpGetIEProxyConfigForCurrentUser(ref WinhttpCurrentUserIeProxyConfig pProxyConfig);
public static string GetProxyForUrl(string reqUrl)
{
var config = new WinhttpCurrentUserIeProxyConfig();
WinHttpGetIEProxyConfigForCurrentUser(ref config);
// System.Console.WriteLine("Proxy: {0}", config.Proxy); // eg. 104.129.192.32:443
// System.Console.WriteLine("AutoConfigUrl: {0}", config.AutoConfigUrl); // http://xxxxx/nam.filt.pac
// System.Console.WriteLine("AutoDetect: {0}", config.AutoDetect); // True
// System.Console.WriteLine("ProxyBypass: {0}", config.ProxyBypass); // *.microsoft.com;*.corp.com;*.dev.microsoft.com;*.ms.com;*.local;<local>
var w = System.Net.WebRequest.GetSystemWebProxy();
var url = new System.Uri(reqUrl);
if (w.IsBypassed(url)) return "DIRECT";
return w.GetProxy(url).ToString();
}
}
"@
if ($reqUrl.length -eq 0) {
echo "Missing argument"
echo "getSystemProxyForUrl.ps1 -- will determine the proxy to be used for the given url"
echo "Example:"
echo " powershell .\getSystemProxyForUrl.ps1 http://microsoft.com"
echo "Outputs proxy url to standard out"
echo "or if no proxy is required, outputs the word DIRECT"
exit
}
Add-Type -TypeDefinition $Source -Language CSharp
([WinHttp]::GetProxyForUrl($reqUrl))
您可以在命令提示符或批处理文件中运行它,方式如下:
powershell .\getSystemProxyForUrl.ps1 http://microsoft.com"
请注意,@" "中的部分是所有C#代码,因此想要从C#完成此操作的人只需提取该代码并将URL传递给WinHttp.GetProxyForUrl()。
使用模块:https://www.npmjs.com/package/get-system-proxy-for-url
安装:
$ npm i -S get-system-proxy-for-url
$ yarn add get-system-proxy-for-url
示例代码:
var url = require('url');
var getSystemProxyForUrl = require('get-system-proxy-for-url');
getSystemProxyForUrl("http://google.com")
.then(function(proxy) {
if (proxy === "DIRECT") {
console.log("proxy not required");
} else {
var endpoint = url.parse(proxy);
console.log(endpoint.href);
}
});
有很多原生的C++调用可用于检索这些数据,但是如果您无法调用任意函数,则会很棘手。如果您可以读取注册表,则可以阅读大部分代理信息。请查看\Software\Microsoft\Windows\CurrentVersion\Internet Settings\下的HKLM和HKCU键ProxyEnable、ProxyServer和ProxyOverride。
netsh winhttp show proxy
在Chrome中使用以下URL,您将能够查看您的代理设置
chrome://net-internals/#proxy
打开 regedit.exe 并前往 HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
如果启用了代理,您将在 ProxyServer
下找到地址。
netsh diag show ieproxy
从命令行运行,让你知道正在使用哪个代理服务器