Details on Selected PAC File Functions PDF Print E-mail
Most common functions are covered in the Netscape guide. The following are those that are not effectively covered or are can be used in a different manner.


 isInNet() is a very, very useful function. It is typically used in two different ways: Identifying the client IP address or the host server IP address.


isInNet(myIpAddress(), "a.b.c.d", "w.x.y.z") can be used to check the local IP address of the client machine against a subnet a.b.c.d with the mask of w.x.y.z.. Example:
if (isInNet(myIpAddress(), "", "")) {
return "PROXY"; 


This is a very handy function when you need to make different routing decisions based on the IP address of the client. i.e. different proxies which are geographically distributed, machines on one particular subnet needing special handling based on a special network configuration, etc.  isInNet(host, "a.b.c.d", "w.x.y.z") can be used to check the IP address of the host that the request is going to. This can be somewhat dangerous, however – See the "lessons learned" section before using this. Example: 

if (isInNet(host, "", "")) { 
return "PROXY"; 

shExpMatch and test() Regex Matches

 shExpMatch() is simple function to peform a regex match:

if (shExpMatch(host, "localhost.*")) { ..... }

You can also use a "test" to match a regex. You do this by creating a variable with the regular expression and then testing it against another variable. Example:

reip = /^\d+\.\d+\.\d+\.\d+$/g;if (reip.test(host)) { ..... }

 This can be useful and lets you do a few things a bit more gracefully than shExpMatch. It also lets you re-use the regular expression multiple times without having to enter it each time you need to do a check which can be useful.   I have, however, heard of times when the Regex test matches don't work as effectively as shExpMatch, so test carefully.   


 alert() is a native JavaScript function to create a pop-up on the screen. This can be VERY handy for troubleshooting and diagnostics of a PAC file. Just be aware that EVERY request that is processed through the PAC file will result in a pop-up. Be very cautious how you use it, especially in a PAC file that’s going to be put into production.   One note – I’ve noticed that Firefox doesn’t seem to display alerts as well as IE does.   


alert("I got to this point, something in the PAC file must be broken later”);
Make Text Bigger Make Text Smaller Reset Text Size
Home Details on Selected Functions
Content View Hits : 971945
The Practical Proxy PAC File Guide