Jump to content

Recommended Posts

Posted (edited)

Hi,

 

I am trying to setup a proxy config file.

 

I would like it to be setup like the following.

 

If the IP address of the client is in this range:

172.16.96.1 - 172.16.99.254

Then go to QV proxy server 172.16.96.30

 

If the IP address of the client is in this range:

172.16.16.1 - 172.16.19.254

Then go to KP proxy server 172.16.16.30

 

Then i would like some URLs as exceptions for example google.com

 

This is some code i put together

 

function FindProxyForURL(url, host)
{

// Variable strings to return

var proxy_yes = "QV-PROXY 172.16.96.30:8080";
var proxy_yes = "KP-PROXY 172.16.16.30:8080";
var proxy_no = "DIRECT";

// Execptions for direct connection

if (shExpMatch(url, "http://google.com/*")) { return proxy_no; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "QV-PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "KP-PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

 

 

 

 

Has anybody got any input or corrections please?

Edited by FN-GM
Posted

I don't think you need this:

 

var proxy_yes = "QV-PROXY 172.16.96.30:8080";
var proxy_yes = "KP-PROXY 172.16.16.30:8080";

 

and I think this bit

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "KP-PROXY 172.16.16.30:8080";

 

should just be

 

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "PROXY 172.16.16.30:8080";

  • Thanks 1
Posted (edited)

No we are a split site school with one domain so the DNS is identical on both sites. Each site has its own IP range. We have a proxy on each site. We dont want one site using the proxy server of the other. If i use a round robin it could revert to the wrong proxy server.

 

So you think it should just be this?

 

function FindProxyForURL(url, host)
{


// Execptions for direct connection

if (shExpMatch(url, "http://google.com/*")) { return proxy_no; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "QV-PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "KP-PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

 

 

Thanks allot :)

Edited by FN-GM
Posted
Why can't you use a Group Policy setting apply that to the OU(s) that have machines on that site to say use this proxy for Site X and use this proxy for Site Y? You can even get clever and use GPP to add more funkyness and say all devices named Site1- take this etc ?
Posted (edited)

We have laptops will be traveling and used between the two sites :)

Sometimes they may move upto 3 times a day. So i can't keep switching OU's for them.

 

We will also have devices that wont be managed by AD.

 

Thanks though, i did think of that.

Edited by FN-GM
Posted (edited)

You don't want the QV-, or KP- prefix to PROXY in the return statements. i.e:

 

function FindProxyForURL(url, host)
{


// Execptions for direct connection

if (shExpMatch(url, "http://google.com/*")) { return "DIRECT"; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

 

A good source of information on .pac / wpad files : FindProxyForURL.com - PAC & WPAD Resource

Edited by Iain
proxy_no not defined, so removed
  • Thanks 1
Posted (edited)

Thanks for the link

 

So i put it like this?

 

Thanks

 

function FindProxyForURL(url, host)
{


// Execptions for direct connection

if (shExpMatch(url, "http://google.com/*")) { return proxy_no; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

Edited by FN-GM
Posted

Yes, I believe so, although you need to replace proxy_no in your google.com test, as this is no longer defined. i.e. it should read:

 

 
if (shExpMatch(url, "http://google.com/*")) { return "DIRECT"; }

 

 

I'd also remove the else statement as it's not needed.

 

Thanks for the link

 

So i put it like this?

 

Thanks

 

function FindProxyForURL(url, host)
{


// Execptions for direct connection

if (shExpMatch(url, "http://google.com/*")) { return proxy_no; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

  • Thanks 1
Posted

Thanks allot :)

 

So its like this?

 

Thanks

 

function FindProxyForURL(url, host)
{


// Execptions for direct connection
if (shExpMatch(url, "http://google.com/*")) { return "DIRECT"; }

// Proxy if PC is on local LAN

if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0"))
return "PROXY 172.16.96.30:8080";

if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0"))
return "PROXY 172.16.16.30:8080";

// Everything else to go direct

else
return "DIRECT";
}

Posted

This should work:

 

function FindProxyForURL(url, host) {

   // Execptions for direct connection
   if (shExpMatch(url, "http://google.com/*")) { 
       return "DIRECT"; 
   }

   // Proxy if PC is on local LAN
   if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0")) {
       return "PROXY 172.16.96.30:8080";
   }
   if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0")) {
       return "PROXY 172.16.16.30:8080";
   }

   // Everything else to go direct
   return "DIRECT";
}

  • Thanks 1
Posted

Thanks one last one if i want to add more URL's do i do it like this please?

 

function FindProxyForURL(url, host) {

   // Execptions for direct connection
   if (shExpMatch(url, "http://google.com/*")) { 
   if (shExpMatch(url, "http://example2.com/*")) { 
       return "DIRECT"; 
   }

   // Proxy if PC is on local LAN
   if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0")) {
       return "PROXY 172.16.96.30:8080";
   }
   if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0")) {
       return "PROXY 172.16.16.30:8080";
   }

   // Everything else to go direct
   return "DIRECT";
}

 

 

 

or

 

 

function FindProxyForURL(url, host) {

   // Execptions for direct connection
   if (shExpMatch(url, "http://google.com/*")) { 
       return "DIRECT"; 
   if (shExpMatch(url, "http://example2.com/*")) { 
       return "DIRECT"; 
   }

   // Proxy if PC is on local LAN
   if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0")) {
       return "PROXY 172.16.96.30:8080";
   }
   if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0")) {
       return "PROXY 172.16.16.30:8080";
   }

   // Everything else to go direct
   return "DIRECT";
}

 

 

Thanks for the help :)

Posted

Like the second one, although you need more } brackets.

 

   // Execptions for direct connection
   if (shExpMatch(url, "http://google.com/*")) { 
       return "DIRECT"; 
   }

   if (shExpMatch(url, "http://example2.com/*")) { 
       return "DIRECT"; 
   }

 

 

So for each url that you don't want to go though the proxy you need:

   if (shExpMatch(url, "")) { 
       return "DIRECT"; 
   }

 

 

Where , is the url that you don't want going through the proxy.

 

Hope that makes sense!

 

Iain

  • Thanks 1
Posted
Why can't you use a Group Policy setting apply that to the OU(s) that have machines on that site to say use this proxy for Site X and use this proxy for Site Y? You can even get clever and use GPP to add more funkyness and say all devices named Site1- take this etc ?

 

Also, it doesn't work for other popular browsers, and non-windows equipment such as staff/student owned iphones etc. Pac files are much more versatile, and they can be defined in Group Policies for domain windows computers.

Posted (edited)

Hi this is my config file. When i set the location of the file in IE, It doesnt seem to point to the proxy server, the traffic isnt going through. Does anyone have any thoughts please?

 

Thanks

 

function FindProxyForURL(url, host) {

   // Execptions for direct connection
   if (shExpMatch(url, "http://google.com/*")) { 
       return "DIRECT"; 
   }
   if (shExpMatch(url, "http://example2.com/*")) { 
       return "DIRECT"; 
   }

   // Proxy if PC is on local LAN
   if (isInNet(myIpAddress(), "172.16.96.1", "255.255.252.0")) {
       return "PROXY 172.16.96.52:8080";
   }
   if (isInNet(myIpAddress(), "172.16.16.1", "255.255.252.0")) {
       return "PROXY 172.16.16.30:8080";
   }

   // Everything else to go direct
   return "DIRECT";
}

Edited by FN-GM
Posted

For those who want to know this is the code i now use and it works :)

 

 
function FindProxyForURL(url, host)

{

//Declare proxy strings as variables

var kpproxy = "PROXY 172.16.16.52:8080";
var qvproxy = "PROXY 172.16.96.52:8080";

// URLS not to use proxy server

if (shExpMatch(url, "*bbc.co.uk*")) { return "DIRECT"; }
if (shExpMatch(url, "*itv.com*")) { return "DIRECT"; }

// Slect Proxy Server

if (isInNet(myIpAddress(), "172.16.16.0", "255.255.252.0")) { return kpproxy; }
if (isInNet(myIpAddress(), "172.16.96.0", "255.255.252.0")) { return qvproxy; }

else

return "DIRECT";

}

  • Thanks 1
Posted

I'm also having a problem with Proxy PAC files I was hoping someone might be able to help me with?

 

My PAC file is located in C:\proxy.pac and both Firefox and Opera work perfectly but IE8 fails, any ideas?

 

 

function FindProxyForURL(url, host)
{
//Declare proxy strings as variables
if (isInNet(myIpAddress(), "10.242.0.0", "255.255.0.0")) { return "PROXY 10.242.163.88:8080"; }
else
return "DIRECT";
}

Posted
In what way does it fail?

"Internet Explorer cannot display the webpage" - If I manually enter the proxy server address and port it works.

 

I've also ran PACtester and that reports the proxy correctly - it seems as if there's some change to the way IE8 uses PAC files?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



  • 43 When would you like EduGeek EDIT 2025 to be held?

    1. 1. Select a time period you can attend


      • I can make it in June\July
      • I can make it in August\Sept
      • Other time period. Comment below
      • Either time

×
×
  • Create New...