Skip to main content

PAC (Proxy Auto-Config) Syntax

info

Please report errors or suggestions through the Mudfish Forums. The examples and explanations in the Korean source were translated or adapted from these references:

The Mudfish browser extension supports the PAC (Proxy Auto-Config) file format.

PAC functions​

Browsers that support PAC generally provide the functions in the format originally specified by Netscape. These functions run in a restricted sandbox; for example, they cannot access the browser's User Agent information.

The following functions are available in the sandbox.

dnsDomainIs​

Tests whether a hostname matches the specified domain and returns true if it does. This is commonly used to define exceptions for particular hosts.

   // Connect directly for google.com and matching subdomains,
// such as maps.google.com and www.google.com.

if (dnsDomainIs(host, "google.com"))
return "DIRECT";

shExpMatch​

Compares a hostname or URL with a shell expression and returns true if it matches.

   // Connect directly for requests matching *.local.

if (shExpMatch(url, "*.local"))
return "DIRECT";

// Connect directly to vpn.domain.com or to files and subdirectories
// under http://abcdomain.com/folder/.

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

isInNet​

Checks whether a host's IP address belongs to the specified subnet. If a hostname is supplied, it is resolved through DNS.

   // Connect directly if the resolved address is in the specified range.

if (isInNet(dnsResolve(host), "172.16.0.0", "255.240.0.0"))
return "DIRECT";

myIpAddress​

Returns the IP address of your computer.

   // Use proxy 10.10.5.1 on port 8080 if this computer is in the given subnet.

if (isInNet(myIpAddress(), "10.10.1.0", "255.255.255.0"))
return "PROXY 10.10.5.1:8080";

dnsResolve​

Resolves a hostname to an IP address through DNS.

   // Connect directly if the resolved host address is in one of these ranges.

if (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), "127.0.0.0", "255.255.255.0"))
return "DIRECT";

isPlainHostName​

Returns true if the hostname contains no dots, as in http://intranet. This can be useful for internal websites.

   // Connect directly for a plain hostname such as http://intranet/
// or http://webserver-name01/.

if (isPlainHostName(host))
return "DIRECT";

localHostOrDomainIs​

Checks whether the hostname matches the specified host or its unqualified name.

   // Connect directly for "www" or "www.google.com".

if (localHostOrDomainIs(host, "www.google.com"))
return "DIRECT";

isResolvable​

Returns true if the hostname can be resolved to an IP address.

Use this function carefully. If name resolution fails, the browser may temporarily become unresponsive.

   // Use proxy1.example.com if the hostname can be resolved through DNS.

if (isResolvable(host))
return "PROXY proxy1.example.com:8080";

dnsDomainLevels​

Returns the number of dots in the hostname. This can be used to create exceptions for internal web servers.

   // Use the proxy if the hostname contains a dot; otherwise connect directly.

if (dnsDomainLevels(host) > 0)
return "PROXY proxy1.example.com:8080";
else
return "DIRECT";

weekdayRange​

Creates rules based on the day of the week, for example to use a proxy only on certain days.

   // Use the proxy from Monday through Friday; otherwise connect directly.

if (weekdayRange("MON", "FRI"))
return "PROXY proxy1.example.com:8080";
else
return "DIRECT";

dateRange​

Creates date-based rules, for example to use a proxy only in certain months.

   // Use the proxy from January through March; otherwise connect directly.

if (dateRange("JAN", "MAR"))
return "PROXY proxy1.example.com:8080";
else
return "DIRECT";

timeRange​

Limits proxy use to a specified time of day.

   // Use the proxy from 8 a.m. to 6 p.m.; otherwise connect directly.

if (timeRange(8, 18))
return "PROXY proxy1.example.com:8080";
else
return "DIRECT";

alert​

This function was not part of the original PAC format. Internet Explorer and Firefox provide it for troubleshooting.

   // Print the DNS resolution result in the browser's error console.

resolved_host = dnsResolve(host);
alert(resolved_host);