Automatically switch IE proxy settings: Simple use IE automatic configuration script

Source: Internet
Author: User
Tags gopher

Because work needs, often need to use the same computer at home and office space, because the home does not need to set the browser proxy, and in the office space need to set. So every time you need to change, the IBM version of Access connections (hereinafter referred to as AC) has been used to switch network settings, very powerful and convenient, but unfortunately the IBM version of AC does not support WIN7, WINDOWS7. The Thinkpadvantage series of AC is notorious for its reputation--causing slow startup. A few IP switching software, but there are few IE agent switching function, Iphelper is to provide IE proxy configuration, but the company's network is the use of "IE automatic configuration Script", set the access to the intranet without the use of agents, to connect the external network to use the agent. But under the in-depth study of this IE automatic configuration script principle, found that it can achieve the function I need (of course, except IP address switching function, but provide this function of the small software to go to the ~), using IE automatic configuration script, you can not have each time in the unit and home manually set IE Agent Only need to add a line of code can ~ (of course, this line of code Hard-won, in fact, learned the computer level two after the C language of children's shoes as long as calm down to look at the following introduction, should be on the IE automatic configuration script clear ~)

1. What is IE automatic configuration script

The role of IE automatic configuration script is that when IE accesses the Web page, it will be accessed according to the content defined in the script file. For example, when you restrict access to some IP using an agent in the script file, accessing some other IP using a different agent, it is very convenient to complete the script file.

2. How to create, edit IE automatic configuration script

1) Create: Open the Notepad with Windows, and save as "after editing the code." PAC format

2) Edit: Use the Notepad with Windows.

3. How to write IE automatic configuration script

The simplest format is a JScript function called FindProxyForURL, IE calls this function by passing in two variables, one is the URL of the user browsing the entire path, and the other is the host name part of this URL.

This FindProxyForURL function has three possible string return values, one is "direct", which is directly connected, not via proxy, and "proxy Proxyaddr:port", where proxyaddr and port are proxy addresses and proxy ports respectively. Three is "SOCKS Socksaddr:port", where socksaddr and port are SOCKS proxy addresses and ports, and an automatic proxy file can be a combination of multiple selections, separated by semicolons (;), such as:

function FindProxyForURL (url,host)

{

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

return "DIRECT";

return "PROXY myproxy:80;

PROXY myotherproxy:8080;

DIRECT ";

}

Save the above code as a Proxy.pac file, such as: C:/proxy.pac, and then in IE's menu "Tools"-> "Intel Options"-> "Connection"-> LAN settings-> the use of automatic configuration scripts selected, Then fill in the Address bar File://c:/proxy.pac, note that the file is a two-slash, to make the settings effective, you need to turn off IE and reopen.

Now we introduce this PROXY.PAC script file, script syntax is JS syntax, JS built-in function can be used, to implement automatic configuration agent, need to implement FindProxyForURL this function, its parameter URL represents the connection to access, host name to access the connection , the function has three return parameters (direct: Directly connected, proxy Ip:port,socket ip:port), and the result case is not sensitive.

Another important application of PAC script is the coexistence of multiple proxy servers, with the control of PAC script, the following goals can be achieved:

So that users randomly choose to use any one of multiple proxy servers to achieve the purpose of traffic load balancing;

Enables the administrator to control the user using the PAC script and not to use a proxy server, so that the proxy server can be free time to maintain;

Let the server work in primary standby mode, and when the primary server is down, it automatically switches to the other standby server without disrupting the service;

Automatically select the best proxy server, depending on the destination of the visit.

Here are a few common PAC functions to illustrate:

<1 isPlainHostName (host), to determine whether the local host, such as http://myservername/access, is a direct connection, otherwise use the proxy

function FindProxyForURL (URL, host)

{

if (isPlainHostName (host))

return "DIRECT";

Else

Return "PROXY proxy:80";

}

<2 dnsDomainIs (Host, ""), localHostOrDomainIs (Host, "") to determine whether the host being accessed belongs to a domain and a domain name, For example, the host name of the. company.com domain, the direct connection between www.company.com and home.company.com, otherwise use proxy 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) to determine whether the accessed host name can be resolved. Example shows whether the host name can be resolved by the DNS server, if it can be directly accessed, or through the proxy access.

function FindProxyForURL (URL, host)

{

if (isresolvable (host))

return "DIRECT";

Else

Return "PROXY proxy:80";

}

<4 isinnet (Host, "", "") to determine whether the IP is within a subnet. Example demonstrates access to the home page of an IP segment without using a proxy.

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, "") to determine whether the accessed host name conforms to a regular expression. This example shows that depending on the host domain name to change the connection type, the local host, *.edu, *.com, respectively, in different ways of connecting.

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 (), takes a substring of the URL string. This example shows that depending on the protocol to choose a different agent, HTTP, HTTPS, FTP, gopher use a different agent 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) resolves the address. This example shows whether the access to the host is an IP, if the use of proxy, otherwise direct connection.

function FindProxyForURL (URL, host)

{

if (dnsresolve (host) = = "166.111.8.237") {

Return "PROXY secproxy:8080";

}

else {

Return "PROXY proxy:80";

}

}

<8 myipaddress (), returns its own IP address. This example shows whether the local IP is an IP, if it is the use of proxy, otherwise directly use the connection.

function FindProxyForURL (URL, host)

{

if (myipaddress () = = "10.1.1.1") {

Return "PROXY proxy:80";

}

else {

return "DIRECT";

}

}

<9 dnsDomainLevels (host), returns the domain name series of the host being accessed. This example demonstrates access to the host's Domain name series is a few levels, is the domain name has several points, if the domain name is somewhat, through the proxy access, otherwise direct connection.

function FindProxyForURL (URL, host)

{

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

Return "PROXY proxy:80";

}

return "DIRECT";

}

<10 Weekdayrange () to determine whether the current date is in a certain period of a week. This example shows the scope of the current date to change the use of the proxy, if it is GMT time from Wednesday to Saturday, use a proxy connection, otherwise direct connection.

function FindProxyForURL (URL, host)

{

if (Weekdayrange ("WED", "SAT", "GMT"))

Return "PROXY proxy:80";

Else

return "DIRECT";

}

<11 The last example is to demonstrate a random use of proxies, so that you can make good use of proxy servers.

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, my solution to the opening question is as follows: (The home network segment IP address is 192.168.1.101, do not set up agents, units need to use Agent test.proxy.com:8080, but the company intranet except)

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: Red bold characters are individual settings, modified as required.

Save these content as C:/myproxy.pac and then in the IE properties-> connection-> LAN settings-> Check the use of automatic configuration script-> fill in file://c:/myproxy.pac-> to determine, you can automatically judge the site online, Of course, this file can also exist on the site, of course, the address should be similar to the HTTP://X.X.X.X/......../PROXY.PAC format. If you are a domain administrator, you can also set this address to an IE automatic configuration script by changing the Group Policy.

-----------------------------------------------------End-----------------------------------------------------------

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.