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)
 2{
 3    if ( dnsDomainIs(host, "localhost") || 
 4         isPlainHostName(host) || 
 5         isInNet(host, "127.0.0.1", "255.255.255.255") )
 6        return "DIRECT";
 7    
 8    if (isInNet(myIpAddress(), "192.168.0.0", "255.255.0.0"))  // HOME
 9        return "DIRECT";
10    
11    if (isInNet(myIpAddress(), "10.1.0.0", "255.255.0.0"))  // CLIENT 1
12        return "PROXY web-proxy:8080";
13}

This means: when I connect to localhost or to 127.0.0.1 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 255.255.0.0 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>



Calendar

June 2005
M T W T F S S
    Jul »
 12345
6789101112
13141516171819
20212223242526
27282930  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening