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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PAC file using java script 1

Status
Not open for further replies.

supportahm1980

Technical User
May 30, 2006
208
US
Not sure if this is the right forum But I am trying to create a pac file (proxy automatic configuration script)

Basially I want subnets 192.168.1.0 and 192.168.40.0 and 192.168.60.0 to use the proxy. But I am not sure how to do a AND statement in javascript.

Does this look ok?
Code:
function FindProxyForURL(url, host) 

{ 

   if (isInNet(myIpAddress(),"192.168.1.0", "255.0.255.0")) && (isInNet(myIpAddress(),"192.168.40.0", "255.0.255.0")) && (isInNet(myIpAddress(),"192.168.160.0", "255.0.255.0")) {

    return "PROXY 127.0.0.1:80"; 

else return "DIRECT"; 

}
 
That's how you do an AND alright, but the statement you're actually getting the script to ask there is:

Is my IP address in the 192.168.1.0 subnet AND the 192.168.40.0 subnet AND the 192.168.60.0 subnet?

Which will only ever return true if the IP address is contained in all three subnets. A bit like if your location was Tokyo AND London AND New York all at the same time.

What you really want to be asking is:
Is my IP address in the 192.168.1.0 subnet OR the 192.168.40.0 subnet OR the 192.168.60.0 subnet?

Replace your && (AND) with || (OR) and you should get better results.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Also the general structure for an if/else block is"
Code:
if(condition){
  code here;
}
else{
  alternate code here;
}

so you might want to move that 'else' outside of the brackets for the 'if'.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
I have changed things around with your help. thank you so much.
Code:
function FindProxyForURL(url, host)
 
if (isInNet(myIpAddress(),"192.168.1.0", "255.0.255.0")) || (isInNet(myIpAddress(),"192.168.40.0", "255.0.255.0")) || (isInNet(myIpAddress(),"192.168.160.0", "255.0.255.0"))
{
return "PROXY 127.0.0.1:80";
}
else {
  return "DIRECT"; 
}
 
Looks much more useful. Glad I could help.

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Enable Apps
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top