BrainDump
  Home arrow BrainDump arrow Page 3 - Controlling Internet Access using a Pac Fi...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Moblin 
JMSL Numerical Library 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
BRAINDUMP

Controlling Internet Access using a Pac File
By: Luke Niland
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 6
    2007-06-26

    Table of Contents:
  • Controlling Internet Access using a Pac File
  • Setting the Proxy server based on the Client subnet
  • Making sure Internal Sites don't use the Proxy
  • Directing Users to your PAC File

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Controlling Internet Access using a Pac File - Making sure Internal Sites don't use the Proxy


    (Page 3 of 4 )

    Now that we have got this far, we are almost ready to send the user to the correct proxy. The only thing we have not done yet is make sure that, if they are trying to access a site on your internal network, they go directly and do not use the proxy. This is done like so:

    if (isInNet(host, "192.168.0.0", "255.255.0.0"))

      {

        return "DIRECT";

      }

    else {

        return proxy;

      }

    The first part of the IF statement is the IsInNet function again, this time on the IP address of the destination passed into the PAC file. If it is in the IP scope specified, then the user is sent directly to the site. At this point the logic of the PAC file concludes and the user is sent to the site.

    If the IF statement returns false, then the user is sent to the proxy server that is currently held in the proxy variable.

    Put it all Together

    Now that we have all the building blocks, we can create our PAC file. If we wish, we can also set it up so that, instead of using the IP address of the proxy, it points to a DNS entry. This is useful if you have backup proxies. In that case, if the main one goes offline you can change the DNS entry to the backup and the clients will be re-directed, without you having to alter the PAC file. We use this in our final completed example.

    function FindProxyForURL(url, host)

    {

      //Set a default proxy if non are returned below

      var proxy = "PROXY 192.168.0.244:8080";

     

      // Test for Prestons subnets

      if (isInNet(myIpAddress(), "192.168.1.0", "255.255.255.0"))

        proxy = "PROXY proxy_preston:8080";

      if (isInNet(myIpAddress(), "192.168.2.0", "255.255.255.0"))

        proxy = "PROXY proxy_preston:8080";

     

      // Test for Londons subnets

      if (isInNet(myIpAddress(), "192.168.3.0", "255.255.255.0"))

        proxy = "PROXY proxy_blackpool:8080";

      if (isInNet(myIpAddress(), "192.168.4.0", "255.255.255.0"))

        proxy = "PROXY proxy_blackpool:8080";

     

      //Now direct the user out through the proxy if not internal site

      if (isInNet(host, "192.168.0.0", "255.255.0.0"))

      {

        return "DIRECT";

      }

      else if (url.substring(0, 24) == "http://www.microsoft.com")

      {

        return "PROXY 159.180.13.52:3128";

      }

      else if (url.substring(0, 5) == "http:")

      {

        return proxy;

      }

      else if (url.substring(0, 4) == "ftp:")

      {

        return proxy;

      }

    }

    More BrainDump Articles
    More By Luke Niland


       · Hi Guys,Hope you find the article interesting, any questions post them...
       · Hi !I found the article very informative and easy to understand :-)One question:...
       · Hi Paal,Glad you like the article. Yes, to go to the web service running on...
       · Thank you for your valuable information. I am very happy to catach this valuable...
       · Hi,I'm a bit confused as to what you are trying to archive. I don't think you...
     

    BRAINDUMP ARTICLES

    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics
    - Microsoft Surface
    - Making Your First Active X Control in Visual...
    - Codes and Packages in Microsoft Project 2007
    - Windows 7: Rumors and Demos
    - XP SP3 Why Me?
    - Breaking Up Your Work in Microsoft Project
    - Breaking Work into Task-Sized Chunks
    - Putting Microsoft`s Worldwide Telescope Unde...
    - Handling Multiple Contracts with Indigo
    - Cleaning Out Your Data in XP
    - Multiple Service Contracts and Indigo





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway