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()

 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(), "10.1.33.0", "255.255.255.0")) {
return "PROXY proxy1.company.net:8000"; 
}

 

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, "192.168.0.0", "255.255.0.0")) { 
return "PROXY proxy1.company.com:8000"; 
}
 

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()

 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.   

Example:

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

Main Menu


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/jcurnow/proxypacfiles.com/proxypac/libraries/joomla/cache/handler/callback.php on line 99

Writing PAC Files


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/jcurnow/proxypacfiles.com/proxypac/libraries/joomla/cache/handler/callback.php on line 99

Sample PAC Files


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/jcurnow/proxypacfiles.com/proxypac/libraries/joomla/cache/handler/callback.php on line 99

References and Tools


Warning: Parameter 1 to modMainMenuHelper::buildXML() expected to be a reference, value given in /home/jcurnow/proxypacfiles.com/proxypac/libraries/joomla/cache/handler/callback.php on line 99

Warning: Creating default object from empty value in /home/jcurnow/proxypacfiles.com/proxypac/modules/mod_stats/helper.php on line 106
Content View Hits : 1070939
The Practical Proxy PAC File Guide