+ Post New Thread
Results 1 to 10 of 10
Scripts Thread, Proxy .Pac File in Coding and Web Development; Hi, I was wondering if i can have a sneaky look at the .pac files you use for your peoxy ...
  1. #1

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,940
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447

    Proxy .Pac File

    Hi,

    I was wondering if i can have a sneaky look at the .pac files you use for your peoxy config please?

    Thanks

  2. #2

    LeMarchand's Avatar
    Join Date
    Jan 2008
    Location
    The deepest pits of hell
    Posts
    2,178
    Thank Post
    303
    Thanked 332 Times in 236 Posts
    Rep Power
    141
    Code:
    function FindProxyForURL(url, host)
    {
    //Variable strings to return
    	var proxy_no = "DIRECT";
    //If specific URL needs to bypass proxy, send traffic direct
    //	if (shExpMatch(url, "http://www.LEA.gov.uk*")) { return proxy_no; }
                  if (shExpMatch(url, "http://access.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://corp-intranet.LEA.gov.uk*")) { return proxy_no; }	
    	if (shExpMatch(url, "http://intranet.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://citrixschools.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://192.School.IPRange.*")) { return proxy_no; }
    	if (shExpMatch(url, "http://localhost*")) { return proxy_no; }
    // If at school, use proxy
    	if (isInNet(myIpAddress(), "192.School.IPRange.0", "255.255.255.0"))
    		return "PROXY proxy.address:8080";
    	else
    		return "DIRECT";
    }
    It could probably be simpler, but it seems to work. You may not need as many exceptions!

  3. Thanks to LeMarchand from:

    FN-GM (5th September 2012)

  4. #3

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,746
    Thank Post
    1,275
    Thanked 1,648 Times in 1,104 Posts
    Blog Entries
    22
    Rep Power
    505
    Sure, well strictly speaking this is our wpad.dat file but its the same

    function FindProxyForURL(url, host){
    if (
    isInNet(host, "", ") ||
    isPlainHostName(host) ||
    localHostOrDomainIs(host, "127.0.0.1") ||
    dnsDomainIs(host, "")
    ){
    return "DIRECT";
    }


    else
    return "PROXY ";
    }

  5. #4

    FN-GM's Avatar
    Join Date
    Jun 2007
    Location
    UK
    Posts
    15,940
    Thank Post
    886
    Thanked 1,693 Times in 1,472 Posts
    Blog Entries
    12
    Rep Power
    447
    Quote Originally Posted by LeMarchand View Post
    Code:
    function FindProxyForURL(url, host)
    {
    //Variable strings to return
    	var proxy_no = "DIRECT";
    //If specific URL needs to bypass proxy, send traffic direct
    //	if (shExpMatch(url, "http://www.LEA.gov.uk*")) { return proxy_no; }
                  if (shExpMatch(url, "http://access.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://corp-intranet.LEA.gov.uk*")) { return proxy_no; }	
    	if (shExpMatch(url, "http://intranet.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://citrixschools.LEA.gov.uk*")) { return proxy_no; }
    	if (shExpMatch(url, "http://192.School.IPRange.*")) { return proxy_no; }
    	if (shExpMatch(url, "http://localhost*")) { return proxy_no; }
    // If at school, use proxy
    	if (isInNet(myIpAddress(), "192.School.IPRange.0", "255.255.255.0"))
    		return "PROXY proxy.address:8080";
    	else
    		return "DIRECT";
    }
    It could probably be simpler, but it seems to work. You may not need as many exceptions!
    How can i modify this to include more than one ip range please?

    Thanks

  6. #5
    Boredguy's Avatar
    Join Date
    Jun 2011
    Location
    Swindon
    Posts
    574
    Thank Post
    3
    Thanked 130 Times in 121 Posts
    Rep Power
    50
    Code:
    function FindProxyForURL(url, host)
    {
    	// See http://www.microsoft.com/technet/prodtechnol/ie/ieak/techinfo/deploy/60/en/corpexjs.mspx?mfr=true for examples
    	var proxyServer = "upstreamproxy.mydomain.com:8080";
    	var bypassList = new Array("exclude1,anotherignoresite.*");
    
    	// Check URL against bypass list
    	for (var i = 0; i < bypassList.length; i++)
    	{
    		var bypassUrl = bypassList[i];
    		// Care! see http://support.microsoft.com/kb/274204 if targeting older versions of IE
    		if (shExpMatch(host, bypassUrl)) {return "DIRECT";}
    	}
    
    	// All other requests go through to the proxy.
    	// should that fail to respond, try direct instead
    	return "PROXY " + proxyServer + "; DIRECT";
    }

  7. #6

    LeMarchand's Avatar
    Join Date
    Jan 2008
    Location
    The deepest pits of hell
    Posts
    2,178
    Thank Post
    303
    Thanked 332 Times in 236 Posts
    Rep Power
    141
    Quote Originally Posted by FN-GM View Post
    How can i modify this to include more than one ip range please?

    Thanks
    You should be able to add exceptions in by just adding another line with the appropriate range:

    Code:
    if (shExpMatch(url, "http://xxx.xxx.xxx.*")) { return proxy_no; }
    As for adding an extra range to use the/another proxy, I've not done it myself, but I would imagine that you could just add in another if statement:

    Code:
    // If at school, use proxy
    	if (isInNet(myIpAddress(), "192.School.IPRange.0", "255.255.255.0"))
    		return "PROXY proxy.address:8080";
               // If at location Y
                  if (isInNet(myIpAddress(), "An.other.range.0", "another.subnet.mask.0"))
    		return "PROXY TheRelevant.address:AndPort";   
    	else
    		return "DIRECT";
    }
    The range number must terminate in a 0.

    P.S. The first line of exceptions in my initial example is commented out for some reason (maybe it's no longer needed, but I left it there as a reminder). Obviously, the // should be removed for it to work.

  8. #7
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    671
    Thank Post
    41
    Thanked 17 Times in 16 Posts
    Rep Power
    22
    I have been trying to get this proxy.pac working for our laptops and I have just drawn a complete blank. The code I am using is quite simple.

    Code:
    function FindProxyForURL(url, host){
    if (isInNet(myIpAddress(), “10.0.48.0?, “255.255.252.0?))
    return “PROXY staffproxy.swgfl.org.uk:8080?;
    else
    return “DIRECT”;
    }
    I have followed several on-line guides all of which are very similar. I have created a second site on my IIS server called "pac" because port 80 was in use I have used port 1500. I have deployed a gpo looking to http://server-ip:1500/proxy.pac That works but the proxy settings are not applied.

    I have also tried using wpad.dat and entering a cname entry that fails too.

    All our clients are Windows 7 with IE8 our servers are 2008R2, the proxy server we use is offsite. Is there an alternative way of getting this solution?

    Also if I enter the file locations directly in the browser that doesn't work either.
    Last edited by edie209; 12th September 2012 at 08:59 PM. Reason: more info

  9. #8

    LeMarchand's Avatar
    Join Date
    Jan 2008
    Location
    The deepest pits of hell
    Posts
    2,178
    Thank Post
    303
    Thanked 332 Times in 236 Posts
    Rep Power
    141
    Assuming those question marks are typos (they should be quotation marks - "), have you tried storing the PACs locally?

    I have to confess that I've never got around to properly publishing the PACs and script a "copy to" location X and use a GPO to point the browser to the file, e.g. file://C:\ProxySettings\MyProxy.pac.

    If nothing else, you could use this on a test machine to check whether it's a problem with the PAC or the publishing method. Ignore me if that's what you meant by:

    Also if I enter the file locations directly in the browser that doesn't work either.

  10. #9

    sparkeh's Avatar
    Join Date
    May 2007
    Posts
    6,746
    Thank Post
    1,275
    Thanked 1,648 Times in 1,104 Posts
    Blog Entries
    22
    Rep Power
    505
    Easiest way to do this is with wpad.
    Quote Originally Posted by edie209 View Post
    I have also tried using wpad.dat and entering a cname entry that fails too.
    Its an A record you need.
    Plus not all browsers work the same - can't remember off the top of my head by some only do dns wapd, some only dhcp wapd, some both - so its worth setting up dhcp + dns methods.
    Here is a fairly straight forward guide: Deploying WPAD « FindProxyForURL - Proxy PAC & WPAD Resource

  11. #10
    edie209's Avatar
    Join Date
    Mar 2006
    Location
    Kernow
    Posts
    671
    Thank Post
    41
    Thanked 17 Times in 16 Posts
    Rep Power
    22
    Thanks for the replies guys

    I have got it working using a different method but not dissimilar to what you suggested LeMarchand, this way I don't have to put the file on each machine.



    user - windows - internet explorer maintenance - automatic browser configuration - enable automatic configuration enabled

    Automatic proxy url (.js .jvs or .pac file) file://\\location-of-share\wpad.dat


    Only thought I have had iswhat happens when it can't see the share? does the browser just assume there are no proxy settings.

SHARE:
+ Post New Thread

Similar Threads

  1. Proxy .pac file
    By FN-GM in forum Internet Related/Filtering/Firewall
    Replies: 30
    Last Post: 23rd September 2010, 11:34 PM
  2. OSX and Proxy.pac files
    By cookie_monster in forum Mac
    Replies: 0
    Last Post: 28th April 2010, 10:38 AM
  3. .pac files and horrible web proxy sites.
    By itwasntme in forum Internet Related/Filtering/Firewall
    Replies: 4
    Last Post: 10th March 2010, 12:13 PM
  4. Proxy .pac file
    By FN-GM in forum Internet Related/Filtering/Firewall
    Replies: 4
    Last Post: 10th February 2010, 10:33 AM
  5. proxy .pac file
    By sted in forum Windows
    Replies: 12
    Last Post: 24th September 2009, 07:50 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •