Reputation: 3126
I'm in need of finding the proxy settings in IE in order to set up RCUrl. The settings cannot be displayed in IE (the hospital administrators have "greyed" out the entire box). I understand that there is a function available to reveal the proxy settings for IE (WinHttpGetIEProxyConfigForCurrentUser). Since I only know R (statistics) where this function is not available-what is the easiest way to get the output from this function? Can it be called in excel?
//M
Upvotes: 4
Views: 19462
Reputation: 65
Open regedit.exe and head over to HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings
If a Proxy is enabled, you will find the address under ProxyServer
Upvotes: 0
Reputation: 9016
Here's different ways to do it. From R, use system2 to shell out to get this information.
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))
You can then run it from a command prompt or a batch file like so:
powershell .\getSystemProxyForUrl.ps1 http://microsoft.com"
If http://microsoft.com requires a proxy, it will be displayed in "standard out", otherwise it prints the word "DIRECT"
Note that, the section in @" "@ is all C# code, so someone who wants to do this from C#, just extract that code and pass the url to WinHttp.GetProxyForUrl()
Use module: https://www.npmjs.com/package/get-system-proxy-for-url
Install:
$ npm i -S get-system-proxy-for-url
$ yarn add get-system-proxy-for-url
Example code:
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);
}
});
Upvotes: 2
Reputation: 548
Use the below URL in chrome and you will be able to see your Proxy settings
chrome://net-internals/#proxy
Upvotes: 1
Reputation: 23
netsh diag show ieproxy
run from command line, lets you know what proxy server you're using
Upvotes: -1
Reputation: 57075
There are a number of native C++ calls that are used to retrieve this data, but if you cannot call arbitrary functions, then you're out of luck. If you can read the registry, you can read most of the proxy information. See HKLM and HKCU under \Software\Microsoft\Windows\CurrentVersion\Internet Settings\ the keys ProxyEnable, ProxyServer and ProxyOverride.
Upvotes: 2