How to get proxy settings from IE?

I need to find proxy settings in IE to configure RCUrl. Settings cannot be displayed in IE (hospital administrators “crossed out” the entire box). I understand that there is a function that allows you to identify proxy settings for IE (WinHttpGetIEProxyConfigForCurrentUser). Since I only know R (statistics) where this function is not available - what is the easiest way to get out of this function? Can it be called in excel?

// M

+3
source share
5 answers

There are a number of C ++ native calls that are used to extract this data, but if you cannot call arbitrary functions, 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 \ ProxyEnable, ProxyServer, and ProxyOverride keys.

+2
source

Use the below url in chrome and you can see the proxy settings

chrome://net-internals/#proxy
+1
source

. R system2, .

PowerShell:

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"

http://microsoft.com -, , "DIRECT"

#:

Note that the section in @ "" @ is all C # code, so anyone who wants to do this with C # just extract this code and pass the URL to WinHttp.GetProxyForUrl ()

From NodeJS:

Use module: https://www.npmjs.com/package/get-system-proxy-for-url

Installation:

$ npm i -S get-system-proxy-for-url
$ yarn add get-system-proxy-for-url

Code example:

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);
    }
});
+1
source
netsh diag show ieproxy

run from the command line, lets you know which proxy you are using

0
source

Open the regedit.exe file and ProxyServerat HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet SettingsIf proxy is enabled ProxyServer, you will find the address inProxyServer

0
source

Source: https://habr.com/ru/post/1788999/


All Articles