Networking HowTos
Networking HowTos

Advanced .PAC proxy auto config file example

July 1, 2014 Other

The following example pac proxy auto config file will allow you to bypass the proxy server for all local IP addresses, and also set exclusions on specific domain names.

 

For information on what a PAC file is, please check out:

 

What is a .pac proxy auto config file

 

 

Advanced .PAC proxy auto config file example:

 

function FindProxyForURL(url, host) {
    var ProxyServer     = "PROXY 192.168.123.1:3128; DIRECT"; //Proxy server to use for HTTP/HTTPS.
    //var ProxyServer     = "PROXY 192.168.123.1:3128"; //Use this if you want to prevent falling back to "DIRECT" if the proxy isnt accessible.
    var FTPProxy        = "DIRECT";    //Proxy server to use for FTP (No proxy in this example)
    var LocalSubnet     = "192.168.123.0";   //The network address for your local IP
    var LocalSubnetMask = "255.255.255.0;    //Subnet mask for your local network
    //set up a list of urls you want direct access to. you can use regular expressions.
    var DirectHosts = [
        "*.microsoft.com*",
        "*.facebook.com*"
    ];
    //Checks if the request is for a FTP site. Use the FTPProxy setting if so.
    if (url.substring(0,3)=="ftp") {
        return FTPProxy;
    }
    //Checks to see if the IP address is on the local subnet,
    //
    if (isInNet(dnsResolve(host), LocalSubnet, LocalSubnetMask)) {
        return "DIRECT";
    }
    //Checks if there are no dots in the hostname. (indicating a site on a local LAN)
    if (isPlainHostName(host)) {
        return "DIRECT";
    }
    //Check all the enteries in the DirectHosts array.
    for (var i in DirectHosts) {
        if (shExpMatch(host, DirectHosts[i])) {
            return "DIRECT";
        }
    }
    //use the default proxy specified at the top as ProxyServer.
    return ProxyServer;
}

You Might Also Like