≡ Menu

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 http://debian.osuosl.org/debian/ 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 http://pactester.googlecode.com/files/pactester-1.0.8.tar.gz

Sample outputs:

--2012-11-20 21:34:17--  http://pactester.googlecode.com/files/pactester-1.0.8.tar.gz
Resolving pactester.googlecode.com..., 2404:6800:4005:c00::52
Connecting to pactester.googlecode.com||: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]


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 client.ip.address.here

Sample proxy.pac file:

function FindProxyForURL(url, host) {
    // Your proxy server name and port
    var proxyserver = 'squidproxy1.cyberciti.biz.home.net.in:3128';
    //  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 http://www.cyberciti.biz:
$ pactester -p proxy.pac -u http://www.cyberciti.biz
Sample outputs:

PROXY squidproxy1.cyberciti.biz.home.net.in:3128

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


Test setting for a client with IP address
$ pactester -p wpad.dat -c -u http://www.google.com
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:

http://www.cyberciti.biz : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
http://nixcraft.com : DIRECT
https://mail.google.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
https://www.google.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
http://nas03 : DIRECT
http://router1 : DIRECT
http://www.pandora.com : PROXY squidproxy1.cyberciti.biz.home.net.in:3128
Share this tutorial on:
This entry is 3 of 3 in the Squid Proxy Server and Proxy Auto Configuration (PAC) Tutorial series. Keep reading the rest of the series:
  1. HowTo: Configure Squid Proxy Server To Access Pandora In Europe
  2. HowTo: Create a Proxy PAC File
  3. HowTo: Test a Proxy PAC File Syntax With pactester Command
{ 1 comment… add one }
  • I Pay Attention December 22, 2014, 2:58 pm

    From the project home page:

    Important: I have stopped maintaining this version of pactester. Please use the version that comes with ‘pacparser’. -Manu Garg

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , ,