1 2 /** 3 * @name CeL function for net 4 * @fileoverview 5 * 本檔案包含了處理網路傳輸相關功能的 functions。 6 * @since 7 */ 8 9 if (typeof CeL === 'function') 10 CeL.setup_module('application.net', 11 function(library_namespace, load_arguments) { 12 13 14 // nothing required 15 16 17 18 19 /** 20 * null module constructor 21 * @class net 的 functions 22 */ 23 CeL.application.net 24 = function() { 25 // null module constructor 26 }; 27 28 /** 29 * for JSDT: 有 prototype 才會將之當作 Class 30 */ 31 CeL.application.net 32 .prototype = { 33 }; 34 35 36 37 38 39 40 41 42 43 44 /* 45 ** 改用 getNetInfo() 46 47 get host name & IP 2005/3/1 22:32 48 只能用於WinXP, Win2000 server(換個版本指令以及輸出可能就不同!),而且非常可能出狀況! 49 Win98 不能反查,只能 check local IP 50 51 //gethost[generateCode.dLK]='Sleep'; 52 function gethost(host){ 53 var IP,p,c,t,i,f,cmd; 54 // 決定shell cmd 對於 ".. > ""path+filename"" " 似乎不能對應的很好,所以還是使用 "cd /D path;.. > ""filename"" " 55 try{c='%COMSPEC% /U /c "',WshShell.Run(c+'"'),p=WScript.ScriptFullName.replace(/[^\\]+$/,''),c+='cd /D ""'+p+'"" && ',cmd=1;} 56 catch(e){try{c='%COMSPEC% /c ',WshShell.Run(c),p='C:\\';}catch(e){return;}} 57 if(host){ 58 if(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(host))IP=host,host=0; 59 }else{ 60 f='ipconfig.tmp.txt'; 61 WshShell.Run(c+'ipconfig > '+(cmd?'""'+f+'"" "':p+f),0,1); // winipcfg 62 if(t=simpleRead(f=p+f)){ 63 if(i=t.indexOf('PPP adapter'),i!=-1)t=t.slice(i); 64 else if(i=t.indexOf('Ethernet adapter'),i!=-1)t=t.slice(i); 65 if(i=t.indexOf('IP Address'),i!=-1)t=t.slice(i); 66 if(t.match(/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/))IP=RegExp.$1; 67 } 68 try{fso.DeleteFile(f);}catch(e){} 69 if(!IP)return [0,0]; 70 } 71 if(!cmd)return [host,IP]; // Win98沒有nslookup 72 f='qDNS.tmp.txt'; 73 WshShell.Run(c+'nslookup '+(cmd?'""'+(IP||host)+'"" > ""'+f+'"" "':(IP||host)+'>'+p+f),0,1); 74 //try{WScript.Sleep(200);}catch(e){} // /C:執行字串中所描述的指令然後結束指令視窗 (x)因為用/c,怕尚未執行完。 75 if((t=simpleRead(f=p+f)) && t.match(/Server:/)&&t.match(/Address:\s*\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/) ){ 76 t=t.slice(RegExp.lastIndex); 77 host=t.match(/Name:\s*([^\s]+)/)?RegExp.$1:0; 78 IP=t.match(/Address:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/)?RegExp.$1:0; 79 //alert(host+'\n'+IP); 80 }else host=IP=0; 81 try{fso.DeleteFile(f);}catch(e){} 82 return [host,IP]; 83 } 84 */ 85 86 87 88 89 90 91 /* 92 取得方法: 93 wget 94 curl 95 lftp 96 prozilla 97 puf 98 CuteFTPPro.TEConnection 99 100 XMLHttp 101 Msxml2.DOMDocument 102 InternetExplorer.Application 103 WinHttp.WinHttpRequest.5.1 深入挖掘Windows腳本技術(5) - 網頁特效代碼 - IT學習者 http://www.itlearner.com/Article/2008/4024_5.shtml 104 獲取軟件下載的真實地址!再談獲取Response.redirect重定向的URL-asp教程-asp學習網 http://www.aspxuexi.com/xmlhttp/example/2006-8-8/852.htm 105 106 */ 107 //getURI.ws=0; // window style: 0: hidden, 1: show 108 //getURI.temp_file='C:\\getURI.tmp'; // 指定當檔名具有特殊字元時之暫存檔 109 //getURI.temp_file=function(URI,toFile){return temp_file_path;} 110 getURI.user_agent='Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'; 111 //getURI.referer=''; 112 getURI[generateCode.dLK]='initWScriptObj'; 113 function getURI(URI,toFile){ 114 var _f=arguments.callee,c,tF; 115 if(!/^[\x20-\xff]+$/.test(toFile)) 116 tF=typeof _f.temp_file=='function'?_f.temp_file(URI,toFile):_f.temp_file; 117 _f.cmd=c= 118 'wget.exe --keep-session-cookies --referer="' 119 +(typeof _f.referer=='string'?_f.referer:URI) 120 +'" --output-document="' 121 +(tF||toFile) 122 +(_f.user_agent?'" --user-agent="'+_f.user_agent:'') 123 +'" "'+URI+'"'; 124 try{ 125 c=WshShell.Run(c,_f.ws||0,true); 126 if(tF && fso.FileExists(tF)) // 出問題還是照搬 127 fso.MoveFile(tF,toFile); 128 if(c && fso.FileExists(toFile)){ 129 // 需注意出問題過,原先就存在的情況。 130 if(!fso.FileExists(toFile+'.unfinished')) 131 fso.MoveFile(toFile,toFile+'.unfinished'); 132 } 133 return c; 134 135 }catch(e){ 136 if((e.number&0xFFFF)==2) 137 return 7; // '找不到執行檔: wget。您可能需要安裝此程式後再執行。' http://users.ugent.be/~bpuype/wget/ 138 return e; 139 } 140 141 } 142 143 144 145 146 147 /* for get serial Youtube video 148 149 2009/10/18-19 22:09:49 main 150 2009/10/20 22:40:33 to function 151 152 example: 153 154 runCode.setR=0; 155 getURI.ws=1; 156 var i=0,base_directory='D:\\USB\\graduate\\7-1 環境規劃研究\\movie\\大三峡\\' 157 ,d=get_video('9RlvpgkLj-8 SrA2Aumaa3A 1rFiC1FL8hE RnOGhurSmOM lqz6Epp8UgI cRpgU_pz4xs tK31eZ_kYAE cipv9M3ZRxU t_ikkmW0B6I XW_WNd5oThU WxaeQTd5UNg qaHXR_cnYYY tPOuLU0l26o 5JWy-vUpC-A khPySOdT1IA 1wwG1coW_LE gJc0UWNlgU4 U9z7LpFU5CE OkD_eNdAXlI 466JBDiNJZA 48qloGDgtEk ywHtkjHJkOU qjJUAuGcYYY 2XD_zV7smWI q3_ZAVqBxYg -tO0aizbf9A agWpXY1QfYY agWpXY1QfYY Y82DTRuCczw vo_wJMXBTIs t4tzUnmuFqY mqXtLRn4ZwU Ku2Hrc7eIBE wcP8TxQvs-0 aTBFC1i7jSk GdzbL5zVbjo MjOa_GtyWn8 DUrigblNFTU uPB0157JU1I q4EF8Cc6STo qOoi_bnj0dg EPBpJnsNrUk 9MyOhef-hz8 yvccMsJD8ZY Pl7zKTsejQQ LGlGG2T_onc W5aDXj0M-CM i_NUdBTpmZ4 6ulRnzPbTEk GMxRLPkLm8k FrPf88CUhTQ Jcz_8SxdYPw hqs3fc7z8OE 6Wl2qBDXCys _Nvv0uIbQB0 X1r3pdc2hfg DoVGRALYR04 U2wSiDiAALM eR7tQMByTww 5K3vvDszc0k JLNusVIjHZQ j7z6vsvn-Lk TNU7-HtA-PA dWQqKDfjPKg uwEq6PFTXhw kotFR3u13QA 9G8Fehz25Ls IdFKvaj5Poc 1TDiHNsM1kE SRxZPHWZBZM Rn9T_TR2l9E 4P_UNxwpy0w lknvtYmYPzI'.split(' '),base_directory,'D:\\downloads\\'); 158 for(;i<d.length;i++) 159 d[i]=d[i].title+' '+d[i].hash+' '+d[i].url; 160 simpleWrite(base_directory+'list.txt',d.join(NewLine),TristateTrue); 161 162 163 TODO: 164 get more data of video 165 multi task 166 debug: get_video('8bFCwvoICD0','d:\\'); 167 */ 168 169 // get video data 170 get_video.get_data=function(video_hash){ 171 var html=getU('http://kej.tw/flvretriever/?videoUrl='+encodeURIComponent('http://www.youtube.com/watch?v='+video_hash)),title,url,m; 172 173 if(html){ 174 if(m=html.match(/vtitle[^>]+>([^<]+)</)) 175 title=m[1]; 176 if(m=html.match(/outputfield[^>]+>([^<]+)</)) 177 url=HTMLToUnicode(m[1]); 178 179 return { 180 hash:video_hash 181 ,title:title // title/name 182 ,url:url 183 ,extension:'.flv' // what extension 184 }; 185 } 186 }; 187 188 //get_video[generateCode.dLK]='initWScriptObj,getURI,getU,HTMLToUnicode'; 189 function get_video(video_hash_array, base_directory, temp_directory, list_only){ 190 if(!video_hash_array)return; 191 if(!(video_hash_array instanceof Array)) 192 video_hash_array=[video_hash_array]; 193 194 var _f=arguments.callee 195 ,count=video_hash_array.length 196 ,err_count=0 197 ,i=0 198 ,urls={},name_array=[] 199 ,video_data 200 ,fp,t 201 ; 202 203 if(base_directory&&!/[\\\/]$/.test(base_directory)) 204 base_directory+=library_namespace.env.path_separator; 205 206 for(;i<count;i++){ 207 fp='['+(i+1)+'/'+count+'] '+video_hash_array[i]; // for message show 208 209 if((video_data=_f.get_data(video_hash_array[i])) && video_data.url){ 210 name_array.push(t=video_data.title); 211 urls[t]=video_data; 212 213 sl(fp+' [<a href="'+video_data.url+'">'+t+'</a>]'); 214 fp=base_directory+t+video_data.extension; 215 216 if(temp_directory && fso.FileExists(getURI.temp_file=temp_directory+video_data.hash+video_data.extension)) 217 fso.MoveFile(getURI.temp_file,fp); 218 if(fso.FileExists(fp)){ 219 sl('File ['+fp+'] existed.'); 220 continue; 221 } 222 223 //if(temp_directory)sl('temp file: ['+getURI.temp_file+']'); 224 if(!list_only){ 225 if(a=getURI(video_data.url,fp)) 226 err_count++,err(a); 227 //Sleep(9); 228 } 229 }else err_count++,err(fp+(video_data?' ['+video_data.title+']':'')); 230 } 231 232 sl(err_count?'Error: '+err_count+'/'+count:'All '+count+' files done.'); 233 234 // return video data 235 name_array.sort(); 236 237 for(i=0,count=name_array.length,t=[];i<count;i++) 238 t.push(urls[name_array[i]]); 239 240 return t; 241 } 242 243 244 245 246 /* 自動組態設定檔/自動設定網址 247 http://contest.ks.edu.tw/syshtml/proxy-pac.html 248 Proxy Auto-Config File Format http://lyrics.meicho.com.tw/proxy.pac 249 http://openattitude.irixs.org/%E7%BC%96%E5%86%99-pac-proxy-auto-config-%E6%96%87%E4%BB%B6/ 250 http://www.atmarkit.co.jp/fwin2k/experiments/ieproxy/ieproxy_01.html 251 http://www.cses.tcc.edu.tw/~chihwu/proxy-pac.htm 252 you should configure your server to map the .pac filename extension to the MIME type: 253 application/x-ns-proxy-autoconfig 254 255 網域名稱之長度,經punycode轉碼後,不得超過63字元,大約二十個中文字以內。 256 257 FindProxyForURL 將會傳回一個描寫Proxy組態設定的單一字串。假如該字串為空字串,則表示瀏覽器不使用 Proxy 伺服器。 258 假如有多個代理伺服器設定同時存在,則最左邊的設定將第一個使用,直 到瀏覽器無法建立連線才會更換到第二個設定。而瀏覽器將會在30分鐘後 自動對於先前無回應的 PROXY 伺服器重新連線。而瀏覽器將會於一個小時 後自動再連線一次(每一次的重新連線都會增加30分鐘)。 259 如果說所有的 PROXY 伺服器都當掉了,也沒有將 DIRECT 設定在 .pac 檔 案,那麼瀏覽器在嘗試建立連線 20 分鐘後將會詢問是否要暫時忽略 Proxy 服器直接存取網路,下一次詢問的時間則是在 40 分鐘後(注意!每一次 詢問都會增加20分鐘) 260 261 http://www.microsoft.com/technet/prodtechnol/ie/ieak/techinfo/deploy/60/en/corpexjs.mspx?mfr=true 262 The isInNet, isResolvable, and dnsResolve functions query a DNS server. 263 The isPlainHostName function checks to see if there are any dots in the hostname. If so, it returns false; otherwise, the function returns true. 264 The localHostOrDomainIs function is executed only for URLs in the local domain. 265 The dnsDomainIs function returns true if the domain of the hostname matches the domain given. 266 267 DIRECT - 不調用代理,直接連接 268 PROXY host:port - 調用指定代理(host:port) 269 SOCKS host:port - 調用指定SOCKS代理(host:port) 270 如果是選用由分號分割的多塊設置,按照從左向右,最左邊的代理會被最優先調用,除非瀏覽器無法成功和proxy建立連接,那麼下一個配置就會被調 用。如果瀏覽器遇到不可用的代理服務器,瀏覽器將在30分鐘後自動重試先前無響應的代理服務器,一個小時後會再次進行嘗試,依此類推,每次間隔時間為 30 分鐘。 271 */ 272 function FindProxyForURL(url, host){ // url: 完整的URL字串, host: 在 URL字串中遠端伺服器的網域名稱。該參數祇是為了 方便而設定的,是與URL在 :// 和 / 中的文字是一模 一樣。但是傳輸阜(The port number)並不包含其中 。當需要的時候可以從URL字串解讀出來。 273 var lch = host.toLowerCase(); 274 275 //isPlainHostName(lch) || isInNet(lch,"192.168.0.0","255.255.0.0") || isInNet(lch,"127.0.0.0","255.255.0.0") || dnsDomainIs(lch,".tw") ?"DIRECT"; 276 return //dnsDomainIs(lch,"holyseal.net") || dnsDomainIs(lch,".fuzzy2.com") ? "PROXY 211.22.213.114:8000; DIRECT": // 可再插入第二、三順位的proxy 277 /* 278 http://www.cybersyndrome.net/ 279 280 http://www.publicproxyservers.com/page1.html 281 curl --connect-timeout 5 -x 219.163.8.163:3128 http://www.getchu.com/ | grep Getchu.com 282 curl --connect-timeout 5 -x 64.34.113.100:80 http://www.getchu.com/ | grep Getchu.com 283 curl --connect-timeout 5 -x 66.98.238.8:3128 http://www.getchu.com/ | grep Getchu.com 284 */ 285 dnsDomainIs(lch,".cn") || dnsDomainIs(lch,"pkucn.com") 286 ? "PROXY proxy.hinet.net:80; DIRECT": // 2009/8/16 14:20:32 用 HiNet 網際網路 Proxy Server 上大陸網速度還滿快的 http://www.ltivs.ilc.edu.tw/proxy/proxy/hinet.htm 287 dnsDomainIs(lch,".getchu.com") ? "PROXY 219.163.8.163:3128; PROXY 64.34.113.100:80; PROXY 66.98.238.8:3128; DIRECT": 288 dnsDomainIs(lch,".minori.ph") ? "PROXY 219.94.198.110:3128; PROXY 221.186.108.237:80; DIRECT": // Japan Distorting Open Proxy List http://www.xroxy.com/proxy--Distorting-JP-nossl.htm 289 // slow: http://www.cybersyndrome.net/country.html 290 dnsDomainIs(lch,".tactics.ne.jp") ? "PROXY 202.175.95.171:8080; PROXY 203.138.90.141:80; DIRECT": 291 //dnsDomainIs(lch,".ys168.com") ? "PROXY 76.29.160.230:8000; DIRECT": // 永硕E盘专业网络硬盘服务 292 293 // 高屏澎區網中心網頁代理伺服器 294 // http://proxy.kpprc.edu.tw/proxy.pac 295 296 // 國立高雄師範大學圖書館 69771202 qwer1234 297 !host.indexOf("140.127.53.") && !url.indexOf("http:") // isInNet(host, "140.127.53.13", "255.255.255.0") 298 || dnsDomainIs(lch,".csis.com.tw") 299 || dnsDomainIs(lch,".ebscohost.com") 300 || dnsDomainIs(lch,".airiti.com") 301 || dnsDomainIs(lch,".cetd.com.tw") 302 || dnsDomainIs(lch,".ceps.com.tw") 303 || dnsDomainIs(lch,"udndata.com") 304 || dnsDomainIs(lch,".wanfangdata.com") 305 || dnsDomainIs(lch,".apabi.com") 306 || dnsDomainIs(lch,".wordpedia.com") 307 || dnsDomainIs(lch,".infolinker.com.tw") 308 ? "PROXY 140.127.53.13:3128; DIRECT": 309 310 "DIRECT";//:/^[a-z\.\d_\-]+$/.test(lch)?"DIRECT":"PROXY dnsrelay.twnic.net.tw:3127"; // http://www.twnic.net.tw/proxy.pac 將中文網域名稱轉成英文網域名稱 311 } 312 313 314 315 316 317 // http://help.globalscape.com/help/cuteftppro8/ 318 //setupCuteFTPSite[generateCode.dLK]='parse_URI'; 319 function setupCuteFTPSite(targetS,site){ 320 if (typeof targetS === 'string') 321 targetS = parse_URI(targetS, 'ftp:'); 322 if (!targetS) 323 return; 324 325 if (site) { 326 try { 327 site.Disconnect(); 328 } catch (e) { 329 } 330 try { 331 site.Close(); 332 } catch (e) { 333 } 334 } 335 try { 336 site = null; 337 site = WScript.CreateObject("CuteFTPPro.TEConnection"); 338 site.Host = targetS.host; 339 // http://help.globalscape.com/help/cuteftppro8/setting_protocols.htm 340 // The default Protocol is FTP, however SFTP (SSH2), FTPS (SSL), HTTP, and HTTPS can also be used. 341 site.Protocol = targetS.protocol.replace(/:$/, '').toUpperCase(); 342 if (targetS.username) 343 site.Login = targetS.username; 344 if (targetS.password) 345 site.Password = targetS.password; 346 347 site.useProxy = "off"; 348 site.TransferType = 'binary'; 349 350 site.Connect(); 351 352 // site.TransferURL("http://lyrics.meicho.com.tw/run.js"); 353 } catch (e) { 354 return; 355 } 356 return site; 357 } 358 359 360 /* 361 TODO: 362 transferURL(remote URI,remote URI) 363 */ 364 transferURL[generateCode.dLK]='parsePath,parse_URI,setupCuteFTPSite'; 365 function transferURL(fromURI,toURI){ 366 //var connectTo=fromURI.indexOf('://')==-1?toURI:fromURI,CuteFTPSite=setupCuteFTPSite(connectTo); 367 var isD,CuteFTPSite,lF,rP; // isD: use download (else upload), lF: local file, rP: remote path 368 if(fromURI.indexOf('://')!=-1)isD=0; 369 else if(toURI.indexOf('://')!=-1)isD=1; 370 else return; // local to local? 371 lF=parsePath(isD?toURI:fromURI); 372 CuteFTPSite=setupCuteFTPSite(rP=parse_URI(isD?fromURI:toURI,'ftp:')); 373 if(!CuteFTPSite||!CuteFTPSite.IsConnected)return; 374 // 到這裡之後,就認定CuteFTPPro.TEConnection的initial沒有問題,接下來若出問題,會嘗試重新initial CuteFTPPro.TEConnection 375 376 // initial local folder 377 try{ 378 if(!site.LocalExists(site.LocalFolder=lF.directory)) 379 site.CreateLocalFolder(lF.directory); 380 }catch(e){return;} 381 site.RemoteFolder=rP.pathname; 382 383 if(isD){ 384 site.Download(rP.fileName,lF.fileName||rP.fileName); 385 if(!site.LocalExists(lF.path))return; 386 }else{ 387 site.Upload(lF.fileName,rP.fileName||lF.fileName); 388 if(!site.LocalExists(rP.path))return; 389 } 390 391 // get list 392 //site.GetList('/OK','','%NAME'); 393 //var l=site.GetResult().replace(/\r\n?/g,'\n').split('\n'); 394 395 // close 396 try{site.Disconnect();}catch(e){} 397 site.Close(); 398 399 return 1; 400 } 401 402 403 404 405 406 407 return ( 408 CeL.application.net 409 ); 410 } 411 412 413 ); 414 415