Working with my laptop on different places I often have to configure network settings. Fortunately I always work on places using DHCP, so this isn’t an issue. But I’ve still to waste time switching the proxy settings in browsers (IE, Firefox, Opera, Maxthon…). Of course there are plugins that handle proxy switching with less effort, but you have to do it manually, and instead it would be great to do it automatically. Every browser do this, automatically, without needing a plugin.

To do that, you have to create a file called proxy.pac in your filesystem, like this one:

 1function FindProxyForURL(url, host)
 3    if ( dnsDomainIs(host, "localhost") || 
 4         isPlainHostName(host) || 
 5         isInNet(host, "", "") )
 6        return "DIRECT";
 8    if (isInNet(myIpAddress(), "", ""))  // HOME
 9        return "DIRECT";
11    if (isInNet(myIpAddress(), "", ""))  // CLIENT 1
12        return "PROXY web-proxy:8080";

This means: when I connect to localhost or to the browser will not have to use any proxy, going DIRECT.
When myIp is in 192.168.*.* don’t use any proxy (as I am @ home). When my ip is 10.1.*.* use “web-proxy:8080″, and so on…
The is the net mask. 255 means perfect match, 0 means ‘anything’ matches (like “*” wildcard).

Once you created this file you go on “Firefox->Connection Settings->Automatic Proxy Configuration URL” and set the path of the proxy.pac file as in this sample: file:///C:/Windows/proxy.pac
Notice that (for mozilla) you have 3 slash.
Using IE, you set it on connection settings as this file://C:\Windows\proxy.pac.
For Opera you set automatic proxy configuration with something like file://C:/Windows/proxy.pac

Then and for the next, when browsing the javascript will be executed and the correct proxy will be automatically selected.

Many apps also get internet settings by IE, so this works well for many apps (MSN messenger, for example). Some others don’t (i.e. gaim, eclipse…). So you still have to do something manually.
Warning: Google Web Accelerator, overwrites proxy settings in IE,using its own proxy.pac file. I won’t use it until they fix this.

There are several tools like NetSwitcher that handle this issue, but they can’t handle any rebellious apps (like gaim and eclipse…).

No Responses to “Automatic Proxy Switching”  

  1. No Comments

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


June 2005
    Jul »

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:



Tag Cloud