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

HowTo: Test a Proxy PAC File Syntax With Syntax Checker

2014年5月11日 baoz 阅读评论

主要注意在build目录下执行install.sh安装依赖的包就好。

原文在http://www.cyberciti.biz/faq/linux-unix-appleosx-bsd-test-proxy-pac-file-syntax/

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.

Installation

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 192.168.1.5:
$ pactester -p wpad.dat -c 192.168.1.5 -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. 本文目前尚无任何评论.