Auto-Proxy Functions Supported by Internet Explorer

ID: Q209266


The information in this article applies to:
  • Microsoft Internet Explorer versions 4.01 Service Pack 2, 5, 5.01 for Windows NT 4.0
  • Microsoft Internet Explorer versions 4.01 Service Pack 2, 5, 5.01 for Windows 95
  • Microsoft Internet Explorer versions 4.01 Service Pack 2, 5, 5.01 for Windows 98
  • Microsoft Internet Explorer version 5.01 for Windows 98 Second Edition


SUMMARY

This article describes the functions understood by Internet Explorer when you use a Proxy AutoConfiguration (.pac) file. The examples included in this article are taken directly from the documentation that is included with the Microsoft Internet Explorer Administration Kit (IEAK).


MORE INFORMATION

You can use a .pac file to centrally control the proxy settings of your browser client. You can set addresses that are bypassed by the proxy server, specify which proxy server the client uses based on the subnet, and specify which proxy server is used depending on the requested Uniform Resource Locator (URL).

The following examples show what you can accomplish using a .pac file.

NOTE: These examples are specified in the IEAK documentation.

JavaScript or JScript Auto-Proxy Examples

The following examples show how you can use a .pac file to specify an auto-proxy URL. To use these functions, you must change the proxy names, port numbers, and Internet Protocol (IP) addresses.

NOTE: The isInNet(), isResolvable(), and dnsResolve() functions query a DNS server.

References to Object Model objects, properties, or methods cause the .pac file to run unsuccessfully. For example, all of the following references cause the .pac file to run unsuccessfully on Internet Explorer:
  • window.open(...)


  • alert(...)


  • password(...)


Example 1: Local Hosts Connect Directly, All Others Connect Through a Proxy

The following function checks to see if the host name is a local host. If the host name is a local host, the function checks to see if the connection is direct. If the host name is not a local host, the connection is through the proxy.

function FindProxyForURL(url, host)
  {
    if (isPlainHostName(host))
      return "DIRECT";
    else
      return "PROXY proxy:80";
  } 
The isPlainHostName() function checks to see if there are any dots in the host name. If so, it returns false; otherwise, it returns true.

Example 2: Hosts Inside the Firewall Connect Directly, Outside Local Servers Connect Through a Proxy

The following function checks to see if the host is either a "plain" host name (meaning the domain name is not included) or part of a particular domain (.company.com), but the host name is neither www nor home.

function FindProxyForURL(url, host)
  {
    if ((isPlainHostName(host) ||
       dnsDomainIs(host, ".company.com")) &&
      !localHostOrDomainIs(host, "www.company.com") &&
      !localHostOrDomainIs(host, "home.company.com"))

      return "DIRECT";
    else
      return "PROXY proxy:80"; 
NOTE: The localHostOrDomainIs() function is run only for URLs in the local domain. The dnsDomainIs() function returns true if the domain of the host name matches the domain that is given.

Example 3: Connect Directly if Host Is Resolvable, Otherwise Connect Through a Proxy

The following function requests that the DNS server resolve the host name that is passed to it. If the DNS server can resolve the host name, a direct connection is made. If the DNS cannot resolve the host name, the connection is made through a proxy. This function is useful when you use an internal DNS server to resolve all internal host names.

function FindProxyForURL(url, host)
  {
    if (isResolvable(host))
      return "DIRECT";
    else
      return "PROXY proxy:80";
  } 
NOTE: The isResolvable() function queries a DNS server.

Example 4: Connect Directly if Host Is in Specified Subnet, Otherwise Connect Through a Proxy

The following function compares a given IP address pattern and mask with the host name. This function is useful if certain hosts in a subnet should be connected directly and others should be connected through a proxy.

function FindProxyForURL(url, host)
  {
    if (isInNet(host, "999.99.9.9", "255.0.255.0"))
      return "DIRECT";
    else
      return "PROXY proxy:80";
  } 
NOTE: The isInNet() function queries a DNS server.

The isInNet function (host, pattern, mask) returns true if the host IP address matches the specified pattern. The mask indicates which part of the IP address to match (255=match, 0=ignore).

Example 5: Determine Connection Type Based on Host Domain

The following function specifies a direct connection if the host is local. If the host is not local, this function determines which proxy to use based on the host domain. This function is useful if the host domain name is one of the criteria for proxy selection.

function FindProxyForURL(url, host)
  {
    if (isPlainHostName(host))
      return "DIRECT";
    else if (shExpMatch(host, "*.com"))
      return "PROXY comproxy:80";
    else if (shExpMatch(host, "*.edu"))
      return "PROXY eduproxy:80";
    else
      return "PROXY proxy";
  } 
The shExpMatch(str, shexp) function returns true if str matches the shexp using shell expression patterns.

Example 6: Determine Connection Type Based on Protocol Being Used

The following function extracts the protocol being used and makes a proxy selection accordingly. If no match is made on the protocol, a direct connection is made. This function is useful if the protocol being used is one of the criteria for proxy selection.

function FindProxyForURL(url, host)
  {
      if (url.substring(0, 5) == "http:") {
        return "PROXY proxy:80";
      }
      else if (url.substring(0, 4) == "ftp:") {
        return "PROXY fproxy:80";
      }
      else if (url.substring(0, 7) == "gopher:") {
        return "PROXY gproxy";
      }
      else if (url.substring(0, 6) == "https:") {
        return "PROXY secproxy:8080";
      }
      else {
        return "DIRECT";
      }
  } 
The substring() function extracts the specified number of characters from a string.

Example 7: Determine Proxy Setting By Checking to See if Host Name Matches IP Address

The following function makes a proxy selection by translating the host name into an IP address and comparing it to a specified string.

function FindProxyForURL(url, host)
  {
      if (dnsResolve(host) == "999.99.99.999") { // = http://secproxy
        return "PROXY secproxy:8080";
      }
      else {
        return "PROXY proxy:80";
      }
  } 
NOTE: The dnsResolve() function queries a DNS server.

Example 8: Connect Through a Proxy if Host IP Address Matches Specified IP Address, Otherwise Connect Directly

The following function is another way to make a proxy selection based on specifying an IP address. This example (unlike example 7) uses the function call to explicitly obtain the numeric IP address (example 7 uses the dnsResolve() function to translate the hostname into the numeric IP address).

function FindProxyForURL(url, host)
  {
      if (myIpAddress() == "999.99.999.99") { 
        return "PROXY proxy:80";
      }
      else {
        return "DIRECT";
      }
  } 
The myIpAddress() function returns the IP address (in integer-dot format) of the host on which the browser is running.

Example 9: Connect Through a Proxy if Any Dots Exist in the Host Name, Otherwise Connect Directly

The following function checks to see how many dots are in the host name. If there are any dots in the host name, the connection is made through a proxy. If there are no dots in the host name, a direct connection is made. This is another way to determine connection types based on host name characteristics.

function FindProxyForURL(url, host)
  {
      if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0
        return "PROXY proxy:80";
      }
        return "DIRECT";
  } 
The dnsDomainLevels() function returns an integer equal to the number of dots in the host name.

Example 10: Specify Days of the Week to Connect Through a Proxy, Other Days Connect Directly

The following function determines the connection type by specifying days of the week that are appropriate for a proxy. Days that do not fall between these parameters use a direct connection. This function is useful in situations where you might want to use a proxy when traffic is heavy and allow a direct connection when traffic is light.

function FindProxyForURL(url, host)
  {
    if(weekdayRange("WED", "SAT", "GMT")) 
     return "PROXY proxy:80";
    else 
     return "DIRECT";
  } 
The weekdayRange( day1 [,day2] [,GMT] ) function tells you if the current system time falls within the range specified by the parameters day1, day2, and GMT. Only the first parameter is necessary. The GMT parameter sets the times to be taken in GMT, rather than in the local time zone.

NOTE: Where the function is called with day1 == day2, previous versions of Internet Explorer yield results that differ from Netscape Navigator. Specifically, previous versions of Internet Explorer interpret this day range as an entire week, while Internet Explorer 5 and Netscape Navigator interpret the range as a single day. For example, if the current day is Monday, the call weekdayRange("TUE", "TUE") returns true on previous versions of Internet Explorer and false on Internet Explorer 5 and Netscape Navigator.

NOTE: The Proxy AutoConfiguration specification is from Netscape. Netscape supports a few more functions that are not listed in the IEAK documentation. These extra functions may not function properly in Internet Explorer. To view the Netscape documentation, visit the following Web site:
http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/proxy-live.html
The third-party contact information included in this article is provided to help you find the technical support you need. This contact information is subject to change without notice. Microsoft in no way guarantees the accuracy of this third-party contact information.

The third-party products discussed in this article are manufactured by vendors independent of Microsoft; we make no warranty, implied or otherwise, regarding these products' performance or reliability.

Additional query words: pac FindProxyForURL jvs js autoproxy fail fails

Keywords : kbenv msiew95 msient msiew98
Version : WINDOWS:4.01 Service Pack 2,5,5.01; Win98:5.01
Platform : WINDOWS Win98
Issue type : kbhowto


Last Reviewed: January 4, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.