HowTo: Test a Proxy PAC File Syntax With Syntax Checker

How can I test a Proxy PAC file syntax under Apple OS X / Linux / *BSD or Unix like operating systems using command line options?

You can use a tool called pactester written in Perl. This tool test Proxy Auto Configuration (PAC) files. From the project home page:

PAC files are used by browsers to determine the ‘right’ proxy for a URL. Since the PAC file evaluation mechanism is generated inside the browser and cannot be accessed from outside, the only way to tell which proxy your browser will use for a specific URL is manual inspection of the PAC file. But manual inspection doesn’t really scale very well. Pactester resolves this problem. It makes use of JavaScript interpreter and Netscape/Mozilla APIs to evaluate the PAC files and automates the whole process. Pactester reads a PAC file, evaluates it in a JavaScript context and uses this PAC file’s logic to determine the proxy for a specific URL.


Debian and Ubuntu Linux user type the following command to install this tool:
$ sudo apt-get install libpacparser1
Sample outputs:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 0 to remove and 11 not upgraded.
Need to get 395 kB of archives.
After this operation, 1,339 kB of additional disk space will be used.
Get:1 squeeze/main libpacparser1 amd64 1.2.6-2 [395 kB]
Fetched 395 kB in 2s (153 kB/s)                       
Selecting previously deselected package libpacparser1.
(Reading database ... 281091 files and directories currently installed.)
Unpacking libpacparser1 (from .../libpacparser1_1.2.6-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libpacparser1 (1.2.6-2) ...

A note about source code installation

Type the following wget command to download the source code:
$ cd /tmp/
$ wget

Sample outputs:

--2012-11-20 21:34:17--
Resolving, 2404:6800:4005:c00::52
Connecting to||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1214308 (1.2M) [application/x-gzip]
Saving to: `pactester-1.0.8.tar.gz'
100%[=============================>] 12,14,308    352K/s   in 3.4s    
2012-11-20 21:34:21 (352 KB/s) - `pactester-1.0.8.tar.gz' saved [1214308/1214308]

Untar the tarball with tar command:
$ tar xvf pactester-1.0.8.tar.gz
Sample outputs:


Install pactester in ~/pactester directory, enter:
$ mkdir $HOME/pactester
$ cd pactester-1.0.8/build/
$ ./ $HOME/pactester

Sample outputs:

Installing /home/vivek/pactester/lib/perl/5.10.1/auto/JavaScript/SpiderMonkey/
Installing /home/vivek/pactester/lib/perl/5.10.1/JavaScript/
Installing /home/vivek/pactester/man/man3/JavaScript::SpiderMonkey.3pm
Appending installation info to /home/vivek/pactester/lib/perl/5.10.1/perllocal.pod
-e ###########################################
>>PERLLIB=-e /home/vivek/pactester/share/perl/5.10.1:/home/vivek/pactester/lib/perl/5.10.1
-e I have set up PERLLIB path in pactester script, so you won't have to
-e set it as an environment variable :)

How do I use pactester command to test proxy auto-config (pac) files?

The syntax is:

pactester -p /path/to/proxy.pac.file -u url
pactester -p /path/to/proxy.pac.file -u url -c

Sample proxy.pac file:

function FindProxyForURL(url, host) {
    // Your proxy server name and port
    var proxyserver = '';
    //  Here's a list of hosts to connect via the PROXY server
    var proxylist = new Array(
    // Return our proxy name for matched domains/hosts
    for(var i=0; i<proxylist.length; i++) {
        var value = proxylist[i];
        if ( localHostOrDomainIs(host, value) ) {
            return "PROXY "+proxyserver;
    return "DIRECT";

To find out proxy string as returned by pac file proxy.pac for the URL
$ pactester -p proxy.pac -u
Sample outputs:


To find out proxy string as returned by pac file proxy.pac for the URL
$ pactester -p proxy.pac -u
Sample outputs:


Test setting for a client with IP address
$ pactester -p wpad.dat -c -u
Create a list of urls/hosts in /tmp/proxy.url.test file:

Now, find out proxy settings for a list of urls specified in /tmp/proxy.url.test file
$ pactester -p /var/www/html/proxy.pac -f /tmp/proxy.url.test
Sample outputs: : PROXY : DIRECT : PROXY : PROXY
http://nas03 : DIRECT
http://router1 : DIRECT : PROXY

Posted by: SXI ADMIN

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.


Start your Bitcoin Exchange with our Software

Start your Bitcoin Exchange with our Software Setup your white label bitcoin exchange right away. Or create your own cryptocurrency using...

How to KVM, QEMU start or stop virtual machine from command line (CLI)

KVM or Kernel Based Virtual Machine is a popular virtualization technology. It allows you to run virtual guest machines over a host machine. To start...

How to Docker backup Saving and restoring your volumes

Running a Docker volume backup First, we spin up a temporary container, and we mount the backup folder and the target Docker volume to this container....