Functions used in PAC files
isPlainHostName()
This function returns true if the hostname contains no dots. Example: http://intranet
Useful when applying exceptions for internal websites that may not require resolution of a hostname to IP address to determine if local.
Useful when applying exceptions for internal websites that may not require resolution of a hostname to IP address to determine if local.
Example:
if (isPlainHostName(host)) return "DIRECT";
dnsDomainIs()
Evaluates hostnames and returns true if hostnames match. Used mainly to match and exception individual host names.
Example:
if (dnsDomainIs(host, ".google.com")) return "DIRECT";
localHostOrDomainIs()
Evaluates hostname and only returns true if an exact hostname match is found.
Example:
if (localHostOrDomainIs(host, "www.google.com")) return "DIRECT";
isResolvable()
Attempts to resolve a hostname to an IP address and returns true if successful. WARNING - This may cause a browser to temporarily hang if a domain is not resolvable.
Example:
if (isResolvable(host)) return "PROXY proxy1.example.com:8080";
isInNet()
This function evaluates the IP address of a hostname and if a specified subnet returns true. If a hostname is passed, the function will resolve the hostname to an IP address.
Example:
if (isInNet(host, "172.16.0.0", "255.240.0.0")) return "DIRECT";
dnsResolve()
Resolves hostnames to an IP address. This function can be used to reduce the number of DNS lookups.
Example:
var resolved_ip = dnsResolve(host);
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
if (isInNet(resolved_ip, "10.0.0.0", "255.0.0.0") ||
isInNet(resolved_ip, "172.16.0.0", "255.240.0.0") ||
isInNet(resolved_ip, "192.168.0.0", "255.255.0.0") ||
isInNet(resolved_ip, "127.0.0.0", "255.255.255.0"))
return "DIRECT";
myIpAddress()
Returns the IP address of the host machine.
Example:
if (isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0")) return "DIRECT";
dnsDomainLevels()
This function returns the number of DNS domain levels (number of dots) in the hostname. Can be used to exception internal websites which use short DNS names, such as: http://intranet
Example:
if (dnsDomainLevels(host) > 0)
return "PROXY proxy1.example.com:8080";
else return "DIRECT";
shExpMatch()
Attempts to match hostname or URL to a specified shell expression and returns true if matched.
Example:
if (shExpMatch(url, "*vpn.domain.com*") ||
shExpMatch(url, "*abcdomain.com/folder/*"))
return "DIRECT";
weekdayRange()
Can be used to specify different proxies for a specific day range. Note: the example employs 'proxy1.example.com' Monday through Friday.
Example:
if (weekdayRange("MON", "FRI"))
return "PROXY proxy1.example.com:8080";
else return "DIRECT";
dateRange()
Can be used to specify different proxies for a specific date range. Note: The example employs 'proxy1.example.com' January through March.
Example:
if (dateRange("JAN", "MAR"))
return "PROXY proxy1.example.com:8080";
else return "DIRECT";
timeRange()
Can be used to specify different proxies for a specific time range. Note: The example employs 'proxy1.example.com' 8 AM to 6 PM.
Example:
if (timeRange(8, 18))
return "PROXY proxy1.example.com:8080";
else return "DIRECT";
Potential PAC function issues
A PAC file may have the following limitations:
dnsResolve
The function dnsResolve (and similar other functions) performs a DNS lookup that can block your browser for a long time if the DNS server does not respond.
If you cache proxy auto-configuration results by domain name in your browser (such as Microsoft's Internet Explorer 5.5 or higher) instead of the path of the URL, it limits the flexibility of the PAC standard. Alternatively, you can disable caching of proxy auto-configuration results by editing the registry.
It is recommended to always use IP addresses instead of host domain names in the isInNet function for compatibility with other Windows components that make use of the Internet Explorer PAC settings, such as .NET 2.0 Framework. For example,
if (isInNet(host, dnsResolve(sampledomain) , "255.255.248.0"))
// .NET 2.0 will resolve proxy properly
if (isInNet(host, sampledomain, "255.255.248.0"))
// .NET 2.0 will not resolve proxy properly
The current convention is to fail over to the direct connection when a PAC file is unavailable. When switching quickly between network configurations (for example, when entering or leaving a VPN), dnsResolve may give outdated results due to DNS caching. For instance, Firefox usually keeps 20 domain entries cached for 60 seconds. This may be configured via the network.dnsCacheEntries and network.dnsCacheExpiration preference variables. Flushing the system's dns cache may also help, (such as by using the sudo service dns-clean start in Linux).
myIpAddress
The myIpAddress function has often been reported to give wrong or unusable results (for example, 127.0.0.1, the IP address of the localhost). It may help to remove any lines referring to the machine hostname on the system's host file (such as /etc/hosts on Linux).
Also, when the browser is Firefox 3 or higher, and the operating system has IPv6 enabled, which is the default in Windows 7 and Vista, the myIpAddress function returns the IPv6 address, which is not usually expected nor programed for in the PAC file.
Some versions of Java have had problems with common proxy PAC file functions such as isInNet(). Please review the Java open issues in the release notes for the versions of Java used by your client browsers.