# Proxy PAC File Javascript



## keamas (26. Sep 2014)

Hallo,

ich möchte gerade ein Proxy Pac File programmieren und habe dabei folgendes Problem:

Das Script sollte den richtigen Proxy wählen abhängig aus welchem Netz der Host kommt.

Allerdings gibt es in dem Script ein paar ausnahmen wie microsoft.com.

Allerdings scheint es als würde das Script diese Zeilen nicht auslesen. Laut meinem Testtol kommt er nie da an.

Kann mir bitte jemand helfen und sagen wo der Fehler hier ist oder habe ich einen Denkfehler drin oder funktioniert das was ich machen will ganz anders?


```
function FindProxyForURL(url, host)
{
    {
        /* The following is a load distribution and failover for the different locations. */
        /* EXAMPLE:
         if (isInNet(myIpAddress(), "10.1.0.0", "255.255.0.0"))
         {
         return "PROXY wcg1.example.com:8080; " + "PROXY wcg2.example.com:8080";
         } */

        //USA
        if (isInNet(myIpAddress(), "10.1.0.0", "255.255.255.0") ||		//Clients
            isInNet(myIpAddress(), "10.2.0.0", "255.255.255.0")) 	    //Servers

        {
            return "PROXY proxy-us.example.com:8080;"
        }

        //Europe
        if (isInNet(myIpAddress(), "10.20.0.0", "255.255.255.0") ||	//Clients
            isInNet(myIpAddress(), "10.21.0.0", "255.255.255.0") ||   //Servers
            isInNet(myIpAddress(), "10.22.0.0", "255.255.255.0") ||    //Developer
            isInNet(myIpAddress(), "10.23.0.0", "255.255.255.0")) 	//Client VPN
        {
            return "PROXY proxy_eu.example.com:8080;"
        }

        /* If no networks matches use the proxy servers. */
        else return "PROXY proxy.example.com:8080";





        /* Normalize the URL for pattern matching
         url = url.toLowerCase();
         host = host.toLowerCase();
         {
         /* Don't proxy local hostnames */


        /* If the requested website is hosted within the internal network, send direct.*/
        if (isPlainHostName(host)) {
            return 'DIRECT';
        }
        /* Don't proxy local domains */
        if (dnsDomainIs(host, ".example1.com") ||
            (host == "example1.com") ||
            dnsDomainIs(host, ".example2.com") ||
            (host == "example2.com") ||
            dnsDomainIs(host, ".example3.com") ||
            (host == "example3.com")) {
            return 'DIRECT';
        }
        /* Don't proxy Windows Update */
        if ((host == "download.microsoft.com") ||
            (host == "ntservicepack.microsoft.com") ||
            (host == "cdm.microsoft.com") ||
            (host == "wustat.windows.com") ||
            (host == "windowsupdate.microsoft.com") ||
            (dnsDomainIs(host, ".windowsupdate.microsoft.com")) ||
            (host == "update.microsoft.com") ||
            (dnsDomainIs(host, ".update.microsoft.com")) ||
            (dnsDomainIs(host, ".windowsupdate.com"))) {
            return 'DIRECT';
        }
        if (isResolvable(host)) {
            var hostIP = dnsResolve(host);
            /* Don't proxy non-routable addresses (RFC 3330) */
            if (isInNet(hostIP, '0.0.0.0', '255.0.0.0') ||
                isInNet(hostIP, '10.0.0.0', '255.0.0.0') ||
                isInNet(hostIP, '127.0.0.0', '255.0.0.0') ||
                isInNet(hostIP, '169.254.0.0', '255.255.0.0') ||
                isInNet(hostIP, '172.16.0.0', '255.240.0.0') ||
                isInNet(hostIP, '192.0.2.0', '255.255.255.0') ||
                isInNet(hostIP, '192.88.99.0', '255.255.255.0') ||
                isInNet(hostIP, '192.168.0.0', '255.255.0.0') ||
                isInNet(hostIP, '198.18.0.0', '255.254.0.0') ||
                isInNet(hostIP, '224.0.0.0', '240.0.0.0') ||
                isInNet(hostIP, '240.0.0.0', '240.0.0.0')) {
                return 'DIRECT';
            }
            /* Don't proxy local addresses.*/
            if (false) {
                return 'DIRECT';
            }
        }
        if (url.substring(0, 5) == 'http:' ||
            url.substring(0, 6) == 'https:' ||
            url.substring(0, 4) == 'ftp:') {
            return 'PROXY proxy.example.com:8080';
        }
        return 'DIRECT';


    }



}
```


----------



## krgewb (24. Feb 2017)

Du hast da ein else:

```
else return "PROXY proxy.example.com:8080";
```


----------



## Thallius (24. Feb 2017)

Ist heute Tag der Leichenfledderer? 

Gruß

Claus


----------

