Code Snippets

The majority of PAC files contain many common elements; this page serves as a resource for documenting common PAC file code snippets.

Local Network Matching

	if (isPlainHostName(host) ||
		shExpMatch(host, "*.local") ||
		isInNet(dnsResolve(host), "10.0.0.0", "255.0.0.0") || 
		isInNet(dnsResolve(host), "172.16.0.0",  "255.240.0.0") ||
		isInNet(dnsResolve(host), "192.168.0.0",  "255.255.0.0") ||
		isInNet(dnsResolve(host), "173.37.0.0",  "255.255.0.0") ||
		isInNet(dnsResolve(host), "127.0.0.0", "255.255.255.0"))
		return "DIRECT";

Host Matching

if (dnsDomainIs(host, "abcdomain.com") || dnsDomainIs(host, "www.abcdomain.com"))
		return "DIRECT";

URL Matching

if (shExpMatch(url, "http://abcdomain.com/folder/*"))
		return "DIRECT";

Protocol Control

// HTTP
if (url.substring(0,5)=="http:") return "DIRECT";
// HTTPS
if (url.substring(0,6)=="https:") return "DIRECT";
// FTP
if (url.substring(0,4)=="ftp:") return "DIRECT";

Defining a connection method

// Direct-to-Internet
return "DIRECT";
// Proxy
return "PROXY proxy.domain.local:8080";
// Failover
return "PROXY proxy1.domain.local:8080; PROXY proxy2.domain.local:8080; DIRECT";

Machine IP Based Routing

    if (isInNet(myIpAddress(), "10.10.5.0", "255.255.255.0"))
        return "PROXY 1.2.3.4:8080";
function FindProxyForURL(url, host) {
			var privateIP = /^(0|10|127|192\.168|172\.1[6789]|172\.2[0-9]|172\.3[01]|169\.254|192\.88\.99)\.[0-9.]+$/;
			var resolved_ip = dnsResolve(host);

			/* Don't send non-FQDN or private IP auths to us */
			if (isPlainHostName(host) || isInNet(resolved_ip, "192.0.2.0","255.255.255.0") || privateIP.test(host))
			return "DIRECT";

			/* FTP goes directly */
			if (url.substring(0,4) == "ftp:")
			return "DIRECT";

			/* Updates are directly accessible */
			if (((localHostOrDomainIs(host, "trust.zscaler.com")) ||
					(localHostOrDomainIs(host, "trust.zscaler.net")) ||
					(localHostOrDomainIs(host, "trust.zscalerone.net")) ||
					(localHostOrDomainIs(host, "trust.zscalertwo.net")) ||
					(localHostOrDomainIs(host, "trust.zscloud.net")) ) &&
				(url.substring(0,5) == "http:" || url.substring(0,6) == "https:"))
			return "DIRECT";

			/* Default Traffic Forwarding. Forwarding to Zen on port 80, but you can use port 9400 also */
			 return "PROXY ${GATEWAY}:80; PROXY ${SECONDARY_GATEWAY}:80; DIRECT";
		}