LAN settings automatic configuration script file and its use _ Other

Source: Internet
Author: User
Tags gopher
Because there are friends in Shenzhen University, their school network is more abnormal. If access to the education network specified free IP IP, per m 6 yuan of money.
I wanted to teach her to use level two agent, but this is too difficult for her. So in case of expediency, I have to let her use IE's automatic configuration script file to limit just in case, at least to ensure that she is using the browser when the Internet is not accidentally access to the charges of IP and slaughter.
Although the school is not so sick, but there are still some, so the automatic configuration script file written out, if there is a need for friends can refer to.
Let's start by introducing the automatic configuration script file:
Open IE, click "Tools"--"Internet Options"--"LAN Settings" and you can see "Using Automatic configuration Scripts"
The role of automatic configuration scripts is that when IE accesses a Web page, it is 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.
A PAC file is actually a text file, the simplest format is to include a JScript function called FindProxyForURL, ie by passing in two variables to call this function, one is the user browse URL full path, one is the host name part of this URL ( Host).
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 ";
}
Here are the functions and instructions that the proxy script might use (English bad friends can skip over to see the application):
PAC Helper functions
dnsDomainIs (host, domain) Returns True if the host is part of the specified domain, false otherwise.
isInNet (hostname, resolves the hostname and subnet IP, subnet mask) returns True if the hostname is within the subnet
specified by the IP address and the subnet mask, false otherwise.
isPlainHostName (host) Returns True if there are no dots in the hostname, false otherwise.
Isresolvable (host) Internet Explorer tries to resolve the hostname through DNS and returns True if successful, false Wise.
localHostOrDomainIs Returns True if the host matches (host, domain) the host portion of the domain, or if the host matches The host and domain portions of the domain, false otherwise. (executed only for URL in the local domain.)
dnsDomainLevels (host) Returns the number of dots in the hostname.
Dnsresolve (host) Returns A string containing the IP address of the specified host.
myIpAddress () Returns A string containing the local machine's IP address.
shExpMatch (URL, shexp) Returns True if the supplied URL matches the specified shell expression, false otherwise.
DateRange (parmlist) Returns True if the current date falls within the dates of specified in Parmlist, False otherwise.
Timerange (parmlist) Returns True if the time falls within of the times specified in Parmlist, False otherwise.
Weekdayrange (parmlist) Returns True if today was within the days of the week specified in Parmlist, False otherwise.
The following are examples of each function application:
Author: Xmudahai 2006-10-17 00:33 reply to this statement
--------------------------------------------------------------------------------
2 automatic configuration script file and its use (original)
A, isPlainHostName (host), this example shows whether the local host, such as http://myservername/
The way to access, if it is a direct connection, otherwise use the proxy
function FindProxyForURL (URL, host)
{
if (isPlainHostName (host))
return "DIRECT";
Else
Return "PROXY proxy:80";
}
B, dnsDomainIs (Host, ""), localHostOrDomainIs (Host, ""), this example demonstrates whether the access host belongs to a domain and a domain name, Use proxy access if the hostname belongs to the. company.com domain and the domain name is not a direct connection to company.com and home.company.com.
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";
}
C, isresolvable (host), this example demonstrates whether the host name can be resolved by the DNS server, if you can directly access, or through the proxy access.
function FindProxyForURL (URL, host)
{
if (isresolvable (host))
return "DIRECT";
Else
Return "PROXY proxy:80";
}
D, isInNet (host, "", ""), this example shows whether access to IP in a subnet, if it is direct access, otherwise, through the proxy, example demo access to Tsinghua IP section of the homepage without agents.
function FindProxyForURL (URL, host)
{
if (isInNet (host, "166.111.0.0", "255.255.0.0"))
return "DIRECT";
Else
Return "PROXY proxy:80";
}
E, shExpMatch (host, ""), this example shows the host domain name to change the type of connection, 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";
}
F, url.substring (), this example shows that according to different protocols to select a different agent, HTTP, HTTPS, FTP, gopher use different agents 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";
}
}
G, Dnsresolve (host), this example to determine whether the access to a host IP, if it is the use of agents, or direct connection.
unction FindProxyForURL (URL, host)
{
if (dnsresolve (host) = = "166.111.8.237") {
Return "PROXY secproxy:8080";
}
else {
Return "PROXY proxy:80";
}
}
H, myIpAddress (), this example demonstrates whether a local IP IP, if it is the use of agents, otherwise directly use the connection.
function FindProxyForURL (URL, host)
{
if (myipaddress () = = "166.111.8.238") {
Return "PROXY proxy:80";
}
else {
return "DIRECT";
}
}
I, dnsDomainLevels (host), this example shows 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";
}
J, Weekdayrange (), this example shows the scope of the current date to change the use of agents, if it is GMT time from Wednesday to Saturday, use the proxy connection, otherwise direct connection.
function FindProxyForURL (URL, host)
{
if (Weekdayrange ("WED", "SAT", "GMT"))
Return "PROXY proxy:80";
Else
return "DIRECT";
}
K, the last example is to demonstrate a random use of the proxy, so that you can take advantage 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
}
}
Using the above functions and examples, you can write more complex and effective automatic proxy scripts.

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.