BrainDump
  Home arrow BrainDump arrow Page 2 - 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 
Mobile Linux 
App Generation ROI 
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 - Setting the Proxy server based on the Client subnet


    (Page 2 of 4 )

    One of the most useful things you can do is send different subnets through different proxies. This is very good for multiple sites that each have their own Internet connection.

    To do this we use a simple if statement to test for the client's IP address, and then set the proxy server based on what is returned, like this:

    // Test for entire subnets

    // if (isInNet(myIpAddress(), "192.168.0.0", "255.255.255.0"))

    // proxy = "PROXY 192.168.0.1:8080";

    This statement uses the function IsInNet to determine whether or not the client's IP address matches the one you specify. In the above code if you are any client on the 192.168.0.0 subnet, the function will return true and set the proxy variable to be 192.168.0.1:8080.

    You can also use a similar block of code to send individual clients to a certain proxy instead of the entire subnet. This could be useful if certain people are heavy Internet users and have a dedicated proxy.

    // Test for individual clients

    if (isInNet(myIpAddress(), "192.168.0.25", "255.255.255.255"))

      proxy = "PROXY 192.168.0.242:8080";

    Of course if you want to use this on certain clients, they will have to have a static IP address.

    Directing Traffic based on URL

    Next we will test for a certain site URL, and if we find the user wants to access that URL we will send them down yet another proxy.

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

      proxy = "PROXY 192.168.0.242:8080";

    This function tests the URL string passed into the PAC file for the website address. The 0, 24 parameters tell the function to start at position 0 from the left hand side of the string, and count 24 characters. If the string matches the function returns true and the proxy variable is set.

    As we are using the Substring function, we can not only test for a specific web site, but specific protocols as well. For instance you might want all of your FTP traffic to go out over a different link from your normal HTTP and HTTPS traffic.

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

      proxy = "PROXY 192.168.0.241:8080";

    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

    - Nilpo`s Top Windows Add-Ons
    - Beginning Silverlight 2.0 Development using ...
    - Fixing Vista`s Troubles
    - Preparing Windows Images for Mass Deployment
    - The Trouble With Vista
    - Slipstreamed and Unattended Windows Installa...
    - Microsoft Office SharePoint Server
    - Microsoft Office SharePoint Designer
    - Microsoft Windows SharePoint Services 3.0
    - Microsoft Live Mesh Overview
    - XAML Brushes and Silverlight
    - Silverlight and XAML Basics
    - Immortal XP
    - XAML Basics
    - Microsoft Surface





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT