局域網(wǎng)設(shè)置自動(dòng)配置腳本文件的寫法與用途
更新時(shí)間:2007年01月24日 00:00:00 作者:
因?yàn)橛信笥言谏钲诖髮W(xué),他們學(xué)校的網(wǎng)絡(luò)比較變態(tài)。如果訪問(wèn)了教育網(wǎng)指定的免費(fèi)IP之外的IP,每M 6元錢。
我本來(lái)想教她用二級(jí)代理之類的,不過(guò)無(wú)奈這個(gè)對(duì)她來(lái)講太難了。所以權(quán)宜之下,我只好讓她使用IE的自動(dòng)配置腳本文件來(lái)限制以防萬(wàn)一,至少能保證她在使用瀏覽器上網(wǎng)的時(shí)候不會(huì)因?yàn)椴恍⌒脑L問(wèn)了收費(fèi)的IP而挨宰。
雖然說(shuō)這么變態(tài)的學(xué)校不多,但是終究還是有的,所以把自動(dòng)配置腳本文件的寫法寫出來(lái),如果有需要的朋友可以參考著來(lái)。
首先我們先來(lái)介紹一下自動(dòng)配置腳本文件:
打開IE,點(diǎn)擊"工具"--"Internet選項(xiàng)"--"局域網(wǎng)設(shè)置",你就可以看到"使用自動(dòng)配置腳本"
自動(dòng)配置腳本起的作用就是,當(dāng)IE訪問(wèn)網(wǎng)頁(yè)的時(shí)候會(huì)根據(jù)腳本文件里面界定的內(nèi)容來(lái)訪問(wèn)。比方說(shuō),你在腳本文件里面限定了訪問(wèn)某些IP使用某個(gè)代理的時(shí)候,訪問(wèn)另外一些IP使用另外的代理,這就很方便通過(guò)腳本文件來(lái)完成。
一個(gè)PAC文件其實(shí)就是一個(gè)文本文件,最簡(jiǎn)單的格式就是包含一個(gè)叫FindProxyForURL的JScript函數(shù),IE通過(guò)傳入兩個(gè)變量來(lái)調(diào)用這個(gè)函數(shù),一個(gè)是用戶瀏覽的地址URL全路經(jīng),一個(gè)是這個(gè)URL中的主機(jī)名部分(host)。
這個(gè)FindProxyForURL函數(shù)有三種可能的字符串返回值,一是"DIRECT",就是直接連接,不通過(guò)代理;二是"PROXY proxyaddr:port",其中proxyaddr和port分別是代理的地址和代理的端口;三是"SOCKS socksaddr:port",其中socksaddr和port分別是socks代理的地址和端口,一個(gè)自動(dòng)代理文件可以是多個(gè)選擇的組合,其中用分號(hào)(;)隔開,如:
function FindProxyForURL(url,host)
{
if (host == "www.mydomain.com")
return "DIRECT";
return "PROXY myproxy:80;
PROXY myotherproxy:8080;
DIRECT";
}
下面是代理腳本可能用到的函數(shù)和說(shuō)明(英文不好的朋友可以直接跳過(guò)去看應(yīng)用):
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 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.
下面是各個(gè)函數(shù)應(yīng)用的例子:
作者: xmudahai 2006-10-17 00:33 回復(fù)此發(fā)言
--------------------------------------------------------------------------------
2 自動(dòng)配置腳本文件的寫法與用途(原創(chuàng))
a、isPlainHostName(host),本例演示判斷是否為本地主機(jī),如 http://myservername/
的方式訪問(wèn),如果是直接連接,否則使用代理
function FindProxyForURL(url, host)
{
if (isPlainHostName(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
b、dnsDomainIs(host, "")、localHostOrDomainIs(host, ""),本例演示判斷訪問(wèn)主機(jī)是否屬于某個(gè)域和某個(gè)域名,如果屬于.company.com域的主機(jī)名,而域名不是company.com和home.company.com的直接連接,否則使用代理訪問(wèn)。
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),本例演示主機(jī)名能否被dns服務(wù)器解析,如果能直接訪問(wèn),否則就通過(guò)代理訪問(wèn)。
function FindProxyForURL(url, host)
{
if (isResolvable(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
d、isInNet(host, "", ""),本例演示訪問(wèn)IP是否在某個(gè)子網(wǎng)內(nèi),如果是就直接訪問(wèn),否則就通過(guò)代理,例子演示訪問(wèn)清華IP段的主頁(yè)不用代理。
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, ""),本例演示根據(jù)主機(jī)域名來(lái)改變連接類型,本地主機(jī)、*.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";
}
f、url.substring(),本例演示根據(jù)不同的協(xié)議來(lái)選擇不同的代理,http、https、ftp、gopher分別使用不同的代理。
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),本例演示判斷訪問(wèn)主機(jī)是否某個(gè)IP,如果是就使用代理,否則直接連接。
unction FindProxyForURL(url, host)
{
if (dnsResolve(host) == "166.111.8.237") {
return "PROXY secproxy:8080";
}
else {
return "PROXY proxy:80";
}
}
h、myIpAddress(),本例演示判斷本地IP是否某個(gè)IP,如果是就使用代理,否則直接使用連接。
function FindProxyForURL(url, host)
{
if (myIpAddress() == "166.111.8.238") {
return "PROXY proxy:80";
}
else {
return "DIRECT";
}
}
i、dnsDomainLevels(host),本例演示訪問(wèn)主機(jī)的域名級(jí)數(shù)是幾級(jí),就是域名有幾個(gè)點(diǎn)如果域名中有點(diǎn),就通過(guò)代理訪問(wèn),否則直接連接。
function FindProxyForURL(url, host)
{
if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0
return "PROXY proxy:80";
}
return "DIRECT";
}
j、weekdayRange(),本例演示當(dāng)前日期的范圍來(lái)改變使用代理,如果是GMT時(shí)間周三到周六,使用代理連接,否則直接連接。
function FindProxyForURL(url, host)
{
if(weekdayRange("WED", "SAT", "GMT"))
return "PROXY proxy:80";
else
return "DIRECT";
}
k、最后一個(gè)例子是演示隨機(jī)使用代理,這樣可以好好利用代理服務(wù)器。
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;
}
}
利用上面的函數(shù)和例子說(shuō)明,大家就可以寫出比較復(fù)雜有效的自動(dòng)代理腳本。
我本來(lái)想教她用二級(jí)代理之類的,不過(guò)無(wú)奈這個(gè)對(duì)她來(lái)講太難了。所以權(quán)宜之下,我只好讓她使用IE的自動(dòng)配置腳本文件來(lái)限制以防萬(wàn)一,至少能保證她在使用瀏覽器上網(wǎng)的時(shí)候不會(huì)因?yàn)椴恍⌒脑L問(wèn)了收費(fèi)的IP而挨宰。
雖然說(shuō)這么變態(tài)的學(xué)校不多,但是終究還是有的,所以把自動(dòng)配置腳本文件的寫法寫出來(lái),如果有需要的朋友可以參考著來(lái)。
首先我們先來(lái)介紹一下自動(dòng)配置腳本文件:
打開IE,點(diǎn)擊"工具"--"Internet選項(xiàng)"--"局域網(wǎng)設(shè)置",你就可以看到"使用自動(dòng)配置腳本"
自動(dòng)配置腳本起的作用就是,當(dāng)IE訪問(wèn)網(wǎng)頁(yè)的時(shí)候會(huì)根據(jù)腳本文件里面界定的內(nèi)容來(lái)訪問(wèn)。比方說(shuō),你在腳本文件里面限定了訪問(wèn)某些IP使用某個(gè)代理的時(shí)候,訪問(wèn)另外一些IP使用另外的代理,這就很方便通過(guò)腳本文件來(lái)完成。
一個(gè)PAC文件其實(shí)就是一個(gè)文本文件,最簡(jiǎn)單的格式就是包含一個(gè)叫FindProxyForURL的JScript函數(shù),IE通過(guò)傳入兩個(gè)變量來(lái)調(diào)用這個(gè)函數(shù),一個(gè)是用戶瀏覽的地址URL全路經(jīng),一個(gè)是這個(gè)URL中的主機(jī)名部分(host)。
這個(gè)FindProxyForURL函數(shù)有三種可能的字符串返回值,一是"DIRECT",就是直接連接,不通過(guò)代理;二是"PROXY proxyaddr:port",其中proxyaddr和port分別是代理的地址和代理的端口;三是"SOCKS socksaddr:port",其中socksaddr和port分別是socks代理的地址和端口,一個(gè)自動(dòng)代理文件可以是多個(gè)選擇的組合,其中用分號(hào)(;)隔開,如:
function FindProxyForURL(url,host)
{
if (host == "www.mydomain.com")
return "DIRECT";
return "PROXY myproxy:80;
PROXY myotherproxy:8080;
DIRECT";
}
下面是代理腳本可能用到的函數(shù)和說(shuō)明(英文不好的朋友可以直接跳過(guò)去看應(yīng)用):
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 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.
下面是各個(gè)函數(shù)應(yīng)用的例子:
作者: xmudahai 2006-10-17 00:33 回復(fù)此發(fā)言
--------------------------------------------------------------------------------
2 自動(dòng)配置腳本文件的寫法與用途(原創(chuàng))
a、isPlainHostName(host),本例演示判斷是否為本地主機(jī),如 http://myservername/
的方式訪問(wèn),如果是直接連接,否則使用代理
function FindProxyForURL(url, host)
{
if (isPlainHostName(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
b、dnsDomainIs(host, "")、localHostOrDomainIs(host, ""),本例演示判斷訪問(wèn)主機(jī)是否屬于某個(gè)域和某個(gè)域名,如果屬于.company.com域的主機(jī)名,而域名不是company.com和home.company.com的直接連接,否則使用代理訪問(wèn)。
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),本例演示主機(jī)名能否被dns服務(wù)器解析,如果能直接訪問(wèn),否則就通過(guò)代理訪問(wèn)。
function FindProxyForURL(url, host)
{
if (isResolvable(host))
return "DIRECT";
else
return "PROXY proxy:80";
}
d、isInNet(host, "", ""),本例演示訪問(wèn)IP是否在某個(gè)子網(wǎng)內(nèi),如果是就直接訪問(wèn),否則就通過(guò)代理,例子演示訪問(wèn)清華IP段的主頁(yè)不用代理。
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, ""),本例演示根據(jù)主機(jī)域名來(lái)改變連接類型,本地主機(jī)、*.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";
}
f、url.substring(),本例演示根據(jù)不同的協(xié)議來(lái)選擇不同的代理,http、https、ftp、gopher分別使用不同的代理。
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),本例演示判斷訪問(wèn)主機(jī)是否某個(gè)IP,如果是就使用代理,否則直接連接。
unction FindProxyForURL(url, host)
{
if (dnsResolve(host) == "166.111.8.237") {
return "PROXY secproxy:8080";
}
else {
return "PROXY proxy:80";
}
}
h、myIpAddress(),本例演示判斷本地IP是否某個(gè)IP,如果是就使用代理,否則直接使用連接。
function FindProxyForURL(url, host)
{
if (myIpAddress() == "166.111.8.238") {
return "PROXY proxy:80";
}
else {
return "DIRECT";
}
}
i、dnsDomainLevels(host),本例演示訪問(wèn)主機(jī)的域名級(jí)數(shù)是幾級(jí),就是域名有幾個(gè)點(diǎn)如果域名中有點(diǎn),就通過(guò)代理訪問(wèn),否則直接連接。
function FindProxyForURL(url, host)
{
if (dnsDomainLevels(host) > 0) { // if number of dots in host > 0
return "PROXY proxy:80";
}
return "DIRECT";
}
j、weekdayRange(),本例演示當(dāng)前日期的范圍來(lái)改變使用代理,如果是GMT時(shí)間周三到周六,使用代理連接,否則直接連接。
function FindProxyForURL(url, host)
{
if(weekdayRange("WED", "SAT", "GMT"))
return "PROXY proxy:80";
else
return "DIRECT";
}
k、最后一個(gè)例子是演示隨機(jī)使用代理,這樣可以好好利用代理服務(wù)器。
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;
}
}
利用上面的函數(shù)和例子說(shuō)明,大家就可以寫出比較復(fù)雜有效的自動(dòng)代理腳本。
相關(guān)文章
腳本發(fā)生錯(cuò)誤怎么解決 當(dāng)前頁(yè)的腳本發(fā)生錯(cuò)誤的解決方法小結(jié)
我們經(jīng)常在訪問(wèn)網(wǎng)頁(yè)的時(shí)候,右下角經(jīng)常出現(xiàn)腳本錯(cuò)誤提示,記得一家國(guó)外的銀行因?yàn)檫@個(gè)原因?qū)е聵I(yè)務(wù)受到很大的影響,如果放到網(wǎng)站上對(duì)用戶也容易產(chǎn)生一些錯(cuò)覺(jué),網(wǎng)站有問(wèn)題,不安全等等疑問(wèn)2011-12-12Verilog關(guān)鍵詞的條件語(yǔ)句實(shí)例詳解
這篇文章主要為大家介紹了Verilog關(guān)鍵詞的條件語(yǔ)句實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04關(guān)于學(xué)習(xí) Flex 的一點(diǎn)建議(轉(zhuǎn)載)
關(guān)于學(xué)習(xí) Flex 的一點(diǎn)建議(轉(zhuǎn)載)...2007-01-01Verilog關(guān)鍵詞的多分支語(yǔ)句實(shí)例詳解
這篇文章主要為大家介紹了Verilog關(guān)鍵詞的多分支語(yǔ)句實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04