Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fastest parse

Status
Not open for further replies.

irbk

MIS
Oct 20, 2004
578
US
So I'm working on a PAC file for proxying my internet connection. I've got several problems to overcome. First is that I've got multiple locations that I want to proxy. I'd like each location to proxy to a local server first, then to a secondary server that's at the central location, and finally if it can't talk to either of those 2 servers, go directly to mcafee. So here is the question, which is faster, doing something like this with a case statment
Code:
function FindProxyForURL(url, host)
{
	// Find your IP address
	var myIP = myIpAddress();
	// Split the IP address into segments
	var ipbits = myIP.split(".");
	// add the first 3 segments together to get a "network" 172.16.1 = 189, 192.168.2 = 362, 192.168.3 = 363, 192.168.4 = 364, etc... 
	var network = parseInt(ipbits[0])+parseInt(ipbits[1])+parseInt(ipbits[2]);
	switch (network) {
		case 189:
			return "PROXY milwaukeeA:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080"; 
			break;
		case 362:
			return "PROXY springfiled:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";
			break;
		case 363:
			return "PROXY atlanta:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";
			break;
		case 364:
			return "PROXY chicago:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";
			break;
		default:
			return "PROXY mydomain.com.interceptor02.mxlogic.net:8080";
	}
}

Or to run a big if/else statement using the "isInNet" method sort of like this:

Code:
function FindProxyForURL(url, host)
{
	var myIP = myIpAddress();
	if(isInNet(myIP, "172.16.1.0", "255.255.255.0"))
			{return "PROXY milwaukeeA:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";} 
	else if(isInNet(myIP, "192.168.2.0", "255.255.255.0"))
		{return "PROXY springfiled:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";}
	else if(isInNet(myIP, "192.168.3.0", "255.255.255.0"))
		{return "PROXY atlanta:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";}
	else if(isInNet(myIP, "192.168.4.0", "255.255.255.0"))
		{return "PROXY chicago:3128; PROXY milwaukeeB:3128; PROXY mydomain.com.interceptor02.mxlogic.net:8080";}
	else
		{return "PROXY mydomain.com.interceptor02.mxlogic.net:8080";}
	}
}
I'm pretty sure that the switch is going to process faster, but wanted some input at the basic level before I got to the big question.

Thanks in advance.
 
Also, which would be faster,
something like this
Code:
if (shExpMatch(url,"*microsoft.com*") ||
		shExpMatch(url,"*windowsupdate.com*") ||
		shExpMatch(url,"*mcafee.com*") ||
		shExpMatch(url,"*mxlogic.net*") ||
		shExpMatch(url,"*mibank.com*") ||
		shExpMatch(url,"*billerweb.com*") ||
		shExpMatch(url,"*ibanking-services.com*"))                  
	{ return "DIRECT"; }
or
Code:
if (dnsDomainIs(host,".microsoft.com") ||
		dnsDomainIs(host,".windowsupdate.com") ||
		dnsDomainIs(host,".mcafee.com") ||
		dnsDomainIs(host,".mxlogic.net") ||
		dnsDomainIs(host,".mibank.com") ||
		dnsDomainIs(host,".billerweb.com") ||
		dnsDomainIs(host,".ibanking-services.com"))                  
	{ return "DIRECT"; }
 
I'm not a JavaScript programmer so most of what I've come up with in the PAC file is from looking at other examples. So I'm not sure which is more efficient, dnsdomainis or shExpMatch when it comes to multiple look-ups. I've got about 25 domain names that currently are in shExpMatch commands and I'm wondering if it would be more efficient for them to be dnsdomainis commands but I'm not sure.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top