Ramblings of a Deranged Mind

pageicon Friday Apr 27, 2007

Proxy Servers

One of the downsides of proxy servers is that most corporate networks have them and most home users don't. Having to remember to switch the proxy servers on and off is difficult because the setting is usually buried several layers deep in the Preferences of the browser.

Two options exist for Firefox/Mozilla/Seamonkey users. The first is to use PrefBar from http://prefbar.mozdev.org/ which puts a preferences bar on the toolbar that you can use to turn your proxy settings on and off with a single click.

After installing PrefBar and restarting your browser, click on Customise, then click on "Proxies" in the left-column and click "Add Item", then click "OK". You'll now have a check box on the PrefBar toolbar that you can use to turn your proxy setting on or off.

The second option and this probably works for IE as well but I haven't tested it, is to use a PAC file. A PAC file is nothing more than a simple JavaScript file with a single function called "FindProxyForURL" that returns a proxy server name for a given URL.

The PAC file that I use is given below, and basically it says if the host is resolvable, i.e. the browser can get an IP address for the host from the local DNS server, then connect directly without a proxy, otherwise use the specified proxy server.

There is a line commented out that checks if the domain of the host ends with ".sun.com" and if it does, go direct, but I found that this breaks sites outside SWAN like www.sun.com and sunsolve.sun.com so I took it out. You can certainly put it back in for specific domains that you know are reacheable directly.

To use this file, save the following lines in a file on your local drive, e.g. proxy.pac, then in your browser, under "Network Settings", in "Automatic proxy configuration URL", put in the path to your local proxy.pac file, e.g. file:///Users/samktan/Documents/proxy.pac or file:///c:/Documents and Settings/samktan/My Documents/proxy.pac. Yes, that is three (3) forward slashes after the file: protocol specifier.

function FindProxyForURL(url, host)
{
    if (isPlainHostName(host) ||
        // dnsDomainIs(host, ".sun.com") ||
        isResolvable(host))
        return "DIRECT";
    else
        return "PROXY webcache.sfbay.sun.com:8080; DIRECT";
}


Now no matter where I go, I don't have to worry about checking my proxy settings, everything just works, as it should be.


Powered by ScribeFire.

Comments:

The function isResolvable(host) will return true if the user is behind a firewall that has a cache DNS (most do, even SWAN : to see this, configure your machine to contact the cache DNS for resolve.). But most of these (including SWAN) do not permit direct HTTP traffic.. I think it may be better to just use return "PROXY webcache.sfbay.sun.com:8080; DIRECT"; for FindProxyForURL.

Posted by rahul on April 27, 2007 at 12:05 PM EST #

There is also a Firefox plugin called switchproxy which allows you to have many proxy definitions and switch between them (or switch proxying off) from the toolbar. I found this really handy when moving between a bunch of customer sites.

Posted by William Hathaway on April 27, 2007 at 01:04 PM EST #

Many thanks to Rahul who pointed out a "flaw" in the isResolvable() function in the PAC file I was using. The intent of the PAC file was to avoid having to turn proxy servers on and off manually, and to have a single proxy PAC file that would allow for direct (no proxy) access to hosts that were directly accessible and to route all others through a proxy server. To date I haven't been able to craft a proxy PAC to achieve this, but the quest goes on.

I took a look at switchproxy but it's Windows-only so I use prefbar.mozdev.org.

Posted by samktan on May 02, 2007 at 08:30 PM EST #

I use FoxyProxy for switching proxies... it can do pattern-based rules and allows you to easily switch from one proxy to another.

Posted by Lewis on May 08, 2007 at 07:33 PM EST #

Post a Comment:
  • HTML Syntax: NOT allowed

« November 2009
SunMonTueWedThuFriSat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
     
       
Today

Feeds

Search this blog

Links

Weblog menu

Today's referrers

Today's Page Hits: 17

Gamertag

WebMap

ip-location

AdSense

Kiva Microloans