IE automatic configuration script

Source: Internet
Author: User
Tags gopher

Because of work requirements, you often need to use the same computer at home and in the office space. Because you do not need to set up a browser proxy at home, you need to set it in the office space. Therefore, you need to modify it every time. Before Windows 7, you have been using the IBM Access Connections (hereinafter referred to as AC) to switch network settings, which is very powerful and convenient, unfortunately, the IBM version of AC does not support WIN7, And the ThinkpAdvantage series of AC is notorious-it will lead to slow boot. There are few IP address switching software, but there are few IE proxy switching functions. iPhone per provides IE proxy configuration, but in the company network, "IE automatic configuration script" is used ", if no proxy is used for Intranet access, the proxy is used for Internet access. Instead, I thoroughly studied the principle of this IE automatic configuration script, and found that it can implement the functions I needed (except for the IP address switching function, of course, however, the small software that provides this function is too busy ~), With the IE automatic configuration script, you do not need to manually set the IE proxy between the organization and the home every time ~ You only need to add a line of code ~ (Of course, this line of code is hard to come by. In fact, the children's shoes who have learned the second-level computer examination and passed the C language just have to calm down and take a look at the following introduction. They should be clear about the automatic configuration script for IE ~)

1. What is an IE automatic configuration script?

The function of automatically configuring scripts for IE is to access the webpage according to the content defined in the script file when IE accesses the webpage. For example, when you access some IP addresses using a proxy in the script file, you can access other IP addresses using another Proxy, which is convenient through the script file.

2. How to create and edit an automatic IE configuration script

1) Create: Open the notepad that comes with WINDOWS, edit the code, and save it as ". PAC"

2) EDIT: Use the notepad that comes with WINDOWS.

3. How to compile the IE automatic configuration script

The simplest format is to include a JScript function called FindProxyForURL. IE calls this function by passing in two variables. The other is the URL path of the user's browser, one is the host name in the URL ).

The FindProxyForURL function has three possible string return values: "DIRECT", DIRECT connection, no PROXY; "PROXY proxyaddr: port ", proxyaddr and port are the proxy address and proxy port respectively, and SOCKS socksaddr: port, where socksaddr and port are the socks proxy address and port respectively, an automatic proxy file can be a combination of multiple options, separated by semicolons (;), such:

Function FindProxyForURL (url, host)

{

If (host = "www.mydomain.com ")

Return "DIRECT ";

Return "PROXY myproxy: 80;

PROXY mytherproxy: 8080;

DIRECT ";

}

Save the preceding code as proxy. pac file, such as: c:/proxy. in the IE menu, choose "Tools"> "INTEL options"> "connection"> LAN Settings> select the automatic configuration script, enter file: // c:/proxy in the address bar. pac. Note that the file is followed by two slashes. To make the setting take effect, You Need To Disable IE and re-open it.

 

Now we will introduce this proxy. in the pac script file, the script syntax is js syntax. js built-in functions can be used. To implement automatic proxy configuration, You need to implement the FindProxyForURL function. The url parameter indicates the connection to be accessed, host indicates the host name to be accessed. This function has three return parameters (direct: direct connection, proxy IP: PORT, socket IP: PORT). The returned results are case-insensitive.

 

Another important application of the PAC script is that when multiple proxy servers coexist, the following goals can be achieved through the control of the pac script:

This allows you to randomly select any of the multiple proxy servers to achieve traffic load balancing;

The Administrator uses the PAC script to control the user's use and does not use a proxy server. In this way, the agent server can be maintained at an empty time;

Enables the server to work in the master-slave mode. When the master server goes down, it automatically switches to other slave servers without interrupting the service;

The best proxy server is automatically selected based on the access destination.

The following describes several common PAC functions:

<1 isPlainHostName (host): determines whether the host is a local host. For example, if the host is accessed through http: // myservername/, the host is connected directly. Otherwise, the proxy is used.

Function FindProxyForURL (url, host)

{

If (isPlainHostName (host ))

Return "DIRECT ";

Else

Return "PROXY proxy: 80 ";

}

<2 dnsDomainIs (host, ""), localHostOrDomainIs (host, ""), to determine whether the accessed host belongs to a domain and a domain name, such as the host name belonging to the .company.com domain, direct Connection Between www.company.com and home.company.com; otherwise, use a proxy for access.

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 ";

}

<3 isResolvable (host): determines whether the accessed host name can be resolved. The example shows whether the host name can be resolved by the dns server. If the host name can be accessed directly, it will be accessed through a proxy.

Function FindProxyForURL (url, host)

{

If (isResolvable (host ))

Return "DIRECT ";

Else

Return "PROXY proxy: 80 ";

}

<4 isInNet (host, "", "") to determine whether the IP address is in a subnet. The example shows that the proxy is not used to access the home page of the IP address segment.

Function FindProxyForURL (url, host)

{

If (isInNet (host, "10.0.0.0", "255.255.0.0 "))

Return "DIRECT ";

Else

Return "PROXY proxy: 80 ";

}

<5 shExpMatch (host, ""): determines whether the accessed host name meets a regular expression. this example shows how to change the connection type based on the host domain name ,*. edu ,*. com uses different connection methods.

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: 80 ";

}

 

<6 url. substring (), the substring of the URL string. in this example, different proxies are selected based on different protocols. http, https, ftp, and gopher use different proxies respectively.

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 ";

}

}

 

<7 dnsResolve (host): Resolve the address. This example shows how to determine whether to access an IP address of the host. If yes, use a proxy. Otherwise, directly connect to the host.

Function FindProxyForURL (url, host)

{

If (dnsResolve (host) = "166.111.8.237 "){

Return "PROXY secproxy: 8080 ";

}

Else {

Return "PROXY proxy: 80 ";

}

}

<8 myIpAddress (): return your own IP address. This example shows how to determine whether the local IP address is an IP address. If yes, use a proxy. Otherwise, use the connection directly.

Function FindProxyForURL (url, host)

{

If (myIpAddress () = "10.1.1.1 "){

Return "PROXY proxy: 80 ";

}

Else {

Return "DIRECT ";

}

}

 

<9 dnsDomainLevels (host) returns the number of domain names of the accessed host. in this example, the number of domain names used to access the host is several, that is, the domain name has several points. If the domain name contains a few points, access the host through a proxy. Otherwise, the host will be connected directly.

Function FindProxyForURL (url, host)

{

If (dnsDomainLevels (host)> 0) {// if number of dots in host> 0

Return "PROXY proxy: 80 ";

}

Return "DIRECT ";

}

 

<10 weekdayRange (): determines whether the current date or day is within a week. this example shows how to change the range of the current date using the proxy. If the GMT time is from Wednesday to Saturday, use the proxy connection. Otherwise, the proxy connection is used.

Function FindProxyForURL (url, host)

{

If (weekdayRange ("WED", "SAT", "GMT "))

Return "PROXY proxy: 80 ";

Else

Return "DIRECT ";

}

 

<11 the last example demonstrates the random use of the proxy server.

Function FindProxyForURL (url, host)

{

Return randomProxy ();

}

Function randomProxy ()

{

Switch (Math. floor (Math. random () * 5 ))

{

Case 0:

Return "PROXY proxy1: 80 ";

Break;

Case 1:

Return "PROXY proxy2: 80 ";

Break;

Case 2:

Return "PROXY proxy3: 80 ";

Break;

Case 3:

Return "PROXY proxy4: 80 ";

Break;

Case 4:

Return "PROXY proxy5: 80 ";

Break;

}

}

 

Finally, I will solve the problem as follows: (the IP address of the home network segment is 192.168.1.101 and no PROXY is set. The Organization needs to use the PROXY TEST. PROXY. COM: 8080, except for the Intranet of the company)

Function FindProxyForURL (url, host)

{

If (myIpAddress () = "192.168.1.101") return "DIRECT ";

Else if (isInNet (host, "XX.0.0.0", "255.0.0.0") return "DIRECT ";

Else if (dnsDomainIs (host, "company") | dnsDomainIs (host, "XXXX.com") return "DIRECT ";

Else if (dnsDomainIs (host, ". CLIENT") | dnsDomainIs (host, ". XXXX") return "DIRECT ";

Else return "PROXY XXX.proxy.com: 8080 ";

}

Note: both red and bold Chinese characters are personal settings and can be modified as needed.

Save the content as c:/myproxy. select IE Properties> connection> LAN Settings> select use automatic configuration script> enter file: // c:/myproxy. pac-> OK, the location can be automatically determined to access the Internet. Of course, this file can also be stored on the website. Of course, the address should be in a format similar to http://x.x.x.x/......./proxy.pac. If you are a domain administrator, you can change the configuration policy to an automatic configuration script for IE.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.