How to setup a Javascript Auto-Proxy script for Internet Explorer

Scenario

You have a Main Office and several Branch Offices in your company. You use proxy servers (like Squid) in every office to save bandwidth and increase browsing performance.

However, your mobile users often call in reporting they cannot access the internet when outside the office.

You once again remind them how to untick the “Use a proxy server for your LAN” setting in Internet Explorer; all the while dreaming of a better solution.

Here’s one such solution:

Solution

Use an Auto-Proxy script to assign the correct Proxy Server, depending on the user’s location. If in the Main or Branch Offices, the correct Proxy Server is assigned. Anywhere else, no Proxy Server is assigned.

We use a script like this at work:

function FindProxyForURL(url, host)
{
	//get ip address of client
	var ip = myIpAddress();

	//if host is not local (fqdn)
	if(!isPlainHostName(host))
	{
		//ip is on Main Office subnet
		if(isInNet(ip, "10.0.0.0", "255.255.255.0"))
		{
			return "PROXY dunprx01.domain.local:3128";
		}
		//ip is on weston subnet
		else if(isInNet(ip, "10.0.1.0", "255.255.255.0"))
		{
			return "PROXY wsmprx01.domain.local:3128";
		}
		//ip is on wakefield subnet
		else if(isInNet(ip, "10.0.2.0", "255.255.255.0"))
		{
			return "PROXY wakprx01.domain.local:3128";
		}
		//ip is on london subnet
		else if(isInNet(ip, "10.0.4.0", "255.255.255.0"))
		{
			return "PROXY lonprx01.domain.local:3128";
		}
		//any other location
		else
		{
			return "DIRECT";
		}
	}
	//internal sites bypass proxy server
	else
	{
	 return "DIRECT";
	}
}

You can test the script by typing the path in the IE LAN settings:

Read more here: http://technet.microsoft.com/en-us/library/dd361950.aspx