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 otherwise.
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 URLs 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 specified in parmList,
false otherwise.
timeRange(parmList) Returns true if the current time falls
within the times specified in parmList,
false otherwise.
weekdayRange(parmList) Returns true if today is within the days
of the week specified in parmList, false
otherwise.
3、下面是各个函数应用的例子:
a、isPlainHostName(host),本例演示判断是否为本地主机,如http://myservername/
的方式访问,如果是直接连接,否则使用代理
function FindProxyForURL(url, host)
{
if (isPlainHostName(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
b、dnsDomainIs(host, "")、localHostOrDomainIs(host, ""),本例演示判断访问主机
是否属于某个域和某个域名,如果属于.company.com域的主机名,而域名不是 www.company.com和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),本例演示主机名能否被dns服务器解析,如果能直接访问,否
则就通过代理访问。
function FindProxyForURL(url, host)
{
if (isResolvable(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
d、isInNet(host, "", ""),本例演示访问IP是否在某个子网内,如果是就直接访问,
否则就通过代理,例子演示访问清华IP段的主页不用代理。
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, ""),本例演示根据主机域名来改变连接类型,本地主机、*.edu、
*.com分别用不同的连接方式。
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";
}
i、dnsDomainLevels(host),本例演示访问主机的域名级数是几级,就是域名有几个点
如果域名中有点,就通过代理访问,否则直接连接。
function FindProxyForURL(url, host)
{
if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0
return "PROXY proxy:80";
}
return "DIRECT";
}