FN-GM Posted September 17, 2010 Report Posted September 17, 2010 (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 September 17, 2010 by FN-GM
CyberNerd Posted September 17, 2010 Report Posted September 17, 2010 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"; 1
CyberNerd Posted September 17, 2010 Report Posted September 17, 2010 BTW - if your trying to load balance? it might be better to do it with RoundRobin DNS - ie Return "PROXY someDNSname:8080"; where someDNSname resolves to 2 different ip ranges.
FN-GM Posted September 17, 2010 Author Report Posted September 17, 2010 (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 September 17, 2010 by FN-GM
john Posted September 17, 2010 Report Posted September 17, 2010 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 ?
FN-GM Posted September 17, 2010 Author Report Posted September 17, 2010 (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 September 17, 2010 by FN-GM
Iain Posted September 17, 2010 Report Posted September 17, 2010 (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 September 17, 2010 by Iain proxy_no not defined, so removed 1
FN-GM Posted September 17, 2010 Author Report Posted September 17, 2010 (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 September 17, 2010 by FN-GM
Iain Posted September 17, 2010 Report Posted September 17, 2010 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"; } 1
FN-GM Posted September 17, 2010 Author Report Posted September 17, 2010 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"; }
Iain Posted September 17, 2010 Report Posted September 17, 2010 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"; } 1
FN-GM Posted September 17, 2010 Author Report Posted September 17, 2010 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
Iain Posted September 17, 2010 Report Posted September 17, 2010 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 1
Iain Posted September 17, 2010 Report Posted September 17, 2010 A useful little tool for testing .pac files is pactester - Project Hosting on Google Code, although you'll need *nix box to run it on. Iain. 2
CyberNerd Posted September 17, 2010 Report Posted September 17, 2010 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.
FN-GM Posted September 20, 2010 Author Report Posted September 20, 2010 (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 September 20, 2010 by FN-GM
steve Posted September 20, 2010 Report Posted September 20, 2010 How are you specifying the PAC file? DHCP option?
CyberNerd Posted September 20, 2010 Report Posted September 20, 2010 I did experience some issues using myIpAddress when using a 22bit subnet mask - worked fine with 24 bit. No help to you at all.
FN-GM Posted September 20, 2010 Author Report Posted September 20, 2010 How are you specifying the PAC file? DHCP option? In IE. Thanks
FN-GM Posted September 21, 2010 Author Report Posted September 21, 2010 Sorry can i just bump this. I was hoping to have this running today Thaks
carvjo Posted September 21, 2010 Report Posted September 21, 2010 Hi You mayhave done this but: Automatic Discovery for Firewall and Web Proxy Clients Regards
FN-GM Posted September 22, 2010 Author Report Posted September 22, 2010 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"; } 1
DarrenShan Posted September 22, 2010 Report Posted September 22, 2010 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"; }
DarrenShan Posted September 22, 2010 Report Posted September 22, 2010 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?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now