Home > 技术点滴 > HowTo: Test a Proxy PAC File Syntax With Syntax Checker

HowTo: Test a Proxy PAC File Syntax With Syntax Checker

May 11th, 2014 baoz Go to comments



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:

Tutorial details
Difficulty Intermediate (rss)
Root privileges Yes/No
Requirements Perl
Estimated completion time N/A

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:

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:

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/
$ ./install.sh $HOME/pactester

Sample outputs:

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

The syntax is:

Sample proxy.pac file:

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:

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:

  1. No comments yet.