Sunday, July 25, 2004

Automatic proxy scripts

Just gonna post it here for easy reference, so I don't have to log into some forum I posted this to just to get it.

This first came up when I needed to use a proxy to access only a site or two (my own ISP was having problems with its DNS). Mozilla had the function of allowing me to use proxy and specify a few sites that could bypass the proxy. I wanted the exact opposite, and it was suggested that I should use a PAC file.

First, enter code similar to the below posted into a plain-text editor, and save it with a .pac extension:

function FindProxyForURL(url, host)   

{
if (shExpMatch(host, "*domain1.com"))
return "PROXY proxy.com:80";
else if (shExpMatch(host, "*domain2.com"))
return "PROXY proxy.com:80";
else
return "DIRECT";
}
By default, Notepad will save the file with a .txt extension, and most Windows systems are set not to display that extension. So most people will have to change their folder options to "show known extensions" in order to change the extension to .pac.

Once that's done, set the browser to use Automatic Proxy (it's usually the last option). Since it asks for the URL, and the file is stored locally, it'll have to look something like file:///C/Folder%20Name/filename.pac.

0 comments: