<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    每日一得

    不求多得,只求一得 about java,hibernate,spring,design,database,Ror,ruby,快速開發
    最近關心的內容:SSH,seam,flex,敏捷,TDD
    本站的官方站點是:顛覆軟件

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      220 隨筆 :: 9 文章 :: 421 評論 :: 0 Trackbacks
    key words:自動腳本 代理腳本 代理 沖出窗子

    本文獻給那些對自動代理腳本有興趣、想自己寫的朋友。

    1、什么是代理腳本(PAC)
    ?一個PAC文件其實就是一個文本文件,最簡單的格式就是包含一個叫FindProxyForURL的
    ?JScript函數,IE通過傳入兩個變量來調用這個函數,一個是用戶瀏覽的地址URL全路經,
    ?一個是這個URL中的主機名部分(host)。這個FindProxyForURL函數有三種可能的字符串
    ?返回值,一是"DIRECT",就是直接連接,不通過代理;二是"PROXY?proxyaddr:port",
    ?其中proxyaddr和port分別是代理的地址和代理的端口;三是"SOCKS?socksaddr:port",
    ?其中socksaddr和port分別是socks代理的地址和端口,一個自動代理文件可以是多個
    ?選擇的組合,其中用分號(;)隔開,如:
    ???
    ???function?FindProxyForURL(url,host)
    ???{
    ?????if?(host?==?"www.mydomain.com")
    ?????????return?"DIRECT";
    ?
    ?????????return?"PROXY?myproxy:80;
    ?????????????????PROXY?myotherproxy:8080;?
    ?????????????????DIRECT";
    ???}
    ???
    ???
    2、下面是代理腳本可能用到的函數和說明:
    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.?

    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";
    ??}
    ??
    ?f、url.substring(),本例演示根據不同的協議來選擇不同的代理,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),本例演示判斷訪問主機是否某個IP,如果是就使用代理,否則直
    ??接連接。
    ??unction?FindProxyForURL(url,?host)
    ??{
    ??????if?(dnsResolve(host)?==?"166.111.8.237")?{
    ????????return?"PROXY?secproxy:8080";
    ??????}
    ??????else?{
    ????????return?"PROXY?proxy:80";
    ??????}
    ??}
    ??
    ??h、myIpAddress(),本例演示判斷本地IP是否某個IP,如果是就使用代理,否則直接使
    ??用連接。
    ??function?FindProxyForURL(url,?host)
    ??{
    ??????if?(myIpAddress()?==?"166.111.8.238")?{?
    ????????return?"PROXY?proxy:80";
    ??????}
    ??????else?{
    ????????return?"DIRECT";
    ??????}
    ??}
    ??
    ??i、dnsDomainLevels(host),本例演示訪問主機的域名級數是幾級,就是域名有幾個點
    ??如果域名中有點,就通過代理訪問,否則直接連接。
    ??function?FindProxyForURL(url,?host)
    ??{
    ??????if?(dnsDomainLevels(host)?>?0)?{?//?if?number?of?dots?in?host?>?0
    ????????return?"PROXY?proxy:80";
    ??????}
    ????????return?"DIRECT";
    ??}
    ??
    ??j、weekdayRange(),本例演示當前日期的范圍來改變使用代理,如果是GMT時間周三
    ??到周六,使用代理連接,否則直接連接。
    ??function?FindProxyForURL(url,?host)
    ??{
    ????if(weekdayRange("WED",?"SAT",?"GMT"))?
    ?????return?"PROXY?proxy:80";
    ????else?
    ?????return?"DIRECT";
    ??}
    ??
    ??k、最后一個例子是演示隨機使用代理,這樣可以好好利用代理服務器。
    ?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;
    ?????}????
    ?}
    ?
    利用上面的函數和例子說明,大家就可以寫出比較復雜有效的自動代理腳本。
    posted on 2006-07-21 14:57 Alex 閱讀(982) 評論(0)  編輯  收藏 所屬分類: network

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 光棍天堂免费手机观看在线观看| 亚洲乱色伦图片区小说| 国产日韩久久免费影院| 亚洲国产专区一区| 黄色a三级免费看| 成人亚洲网站www在线观看| 国产亚洲欧美日韩亚洲中文色| 香蕉视频在线观看免费国产婷婷| ASS亚洲熟妇毛茸茸PICS| 大地资源在线观看免费高清| 亚洲an日韩专区在线| 免费A级毛片无码免费视| 亚洲乱色熟女一区二区三区蜜臀| 性做久久久久免费看| 美女被爆羞羞网站免费| 亚洲中文字幕视频国产| 毛片免费在线观看| 亚洲av永久无码嘿嘿嘿| 三上悠亚亚洲一区高清| 一道本不卡免费视频| 亚洲国产中文字幕在线观看| 免费无码黄网站在线看| 亚洲日本在线观看视频| 在线成人精品国产区免费| 亚洲乱码无限2021芒果| 在线观看免费亚洲| 亚洲免费无码在线| 亚洲福利一区二区三区| 日本牲交大片免费观看| 中文字幕免费在线观看动作大片| 亚洲AV无码国产精品麻豆天美| 天天影视色香欲综合免费| 亚洲国产精品18久久久久久| 国产亚洲精品不卡在线| 100000免费啪啪18免进| 无遮挡a级毛片免费看| 亚洲黄色中文字幕| 免费人成年激情视频在线观看| 毛片在线播放免费观看| 亚洲欧美日韩中文字幕一区二区三区 | 3d成人免费动漫在线观看|