The Blog


Olfeo On-Premise knowledge base
June 5, 2023

How to validate the operation of a .pac proxy using a pactester.


Validate the operation of a .pac proxy using a pactester.


A proxy.pac is used to declare the proxy address and port to client browsers. How can I validate the operation of the declared proxy.pac?

You can check the operation of a .pac proxy using the pacparser tool.

Pacparser is a library for analyzing the automatic proxy configuration of a .PAC file. Automatic proxy configuration files are a widely used proxy configuration method today. Web browsers can use a .PAC file to determine which proxy server to use, or whether a direct connection is required for a given URL. PAC files are written in JavaScript and can be programmed to return different substitution methods (e.g. "PROXY from Proxy1: port; DIRECT" ) depending on the URL, source IP address, protocol, etc.

PAC files open up many new possibilities. PAC files are now a widely accepted method of managing proxies, and companies are using them in the corporate environment. The most popular web browsers support .PAC files.

Since the .PAC proxy file evaluation mechanism is generated inside the browser and cannot be accessed from the outside, the only way to know which proxy the browser will use for a specific URL is by manually inspecting the .PAC proxy file. But manual inspection can be tedious and generate errors proportional to the size of the file.

The idea behind pacparser is to facilitate the analysis of .PAC files (C and python are currently supported).


Step 1

  1. The first step is to install this tool, which is available via the following command for Linux system environments:

    $ sudo apt-get install libpacparser1 python-pacparser libpacparser-dev

    For a Windows or Mac OS X system, go to this address: https: //

  2. To install the pacparser and pactester C library in the Windows environment :

    Download the pacparser -vvv - archive and extract it. A pacparser-v.v.v directory will be created.

  3. Copy all .DLL and pactester.exe files somewhere where the system can find them (e.g. directories that are already in the system path, such as C:\Windows) or simply add the pacparser directory to the system path (PATH).
  4. Link libpacparser.a and pacparser.lib in pacparser with the mingw and Visual Studio compiler tools respectively. Instructions for linking in pacparser on Visual Studio: http: //

Python module

To install the python module of pacparser: download the pacparser - Python25 -vvv - package and extract it. At the command prompt (cmd), go to the pacparser - Python25 -vvv -win32 directory and run install:

C:\temp > cd pacparser - Python25 - 1.0.5 -win32
C:\temp\pacparser - Python25 - 1.0.5 -win32 > install

If it fails for any reason, simply copy the pacparser directory into the python folder: C:\Python25\Lib\site-packages\pacparser.

Step 2

Once the pacparser tool has been installed, you can test the proxy.pac configuration file with python :

Note: If proxypac is hosted on the Olfeo, it must be copied to the client machine on which pacparser is installed.
>>> import pacparser
>>> pacparser.init()
>>> pacparser.parse_pac_file('examples/wpad.dat')
>>> pacparser.find_proxy('', '')
>>> pacparser.find_proxy('', '')
>>> pacparser.cleanup()
Step 3

It is also possible to test the .PAC file using the C language:

manugarg@hobbiton:~$ cat pactest.c
#include <stdio.h>
#include <pacparser.h>

int main(int argc, char* argv[])
  char *proxy;
  proxy = pacparser_find_proxy(argv[2], argv[3]);
  printf("%s\n", proxy);

manugarg@hobbiton:~$ gcc -o pactest pactest.c -lpacparser
manugarg@hobbiton:~$ ./pactest wpad.dat


If the conditions are met, pacparser will return the desired proxy or will return DIRECT (no proxy).

This tool makes it easy to test the conditions of a .PAC file and avoid errors during deployment.