JS版本网站资源状态检测

Title:JS版本网站资源状态检测  --2012-08-28 14:08

前几天需要一个网站状态检测的东东,后面写了个蹩脚的JS版本,里面用到了以前没用过的东西,在这里记下来,其实批处理加curl可以解决得很好,此脚本不能检测网络状态,只能检测网页资源,是否存在异常,如500,400,403错误等。。

---------------------------------------------------------------------------------------------------------

<Html>
<Head>
<Title>Web Request Check   --By Tea</Title>
</Head>
<Body>
 <script Language="JavaScript">
    var xmlHttp;
 var url = "http://www.baidu.com/index.php" //设置请求URL;
 
  function WFile(filename,filecontent)
  { 
   var fso, f, s ; 
    fso = new ActiveXObject("Scripting.FileSystemObject");    
    f = fso.OpenTextFile(filename,8,true); 
    f.WriteLine(filecontent);   
    f.Close(); 
    }
 
  function Start()
  {
    var mydate =new Date();
    var nyr =mydate.getFullYear()+'-'+(mydate.getMonth()+1)+'-'+mydate.getDate();
    var nmt =mydate.getHours()+'.'+mydate.getMinutes();
 
   function xclick() 
   { 
     function xxclick()
     {
      alert('请求的时间:'+mydate.toLocaleString()); 
     }
     if (event.button==2) 
     {
     Start();  //右键弹出时间之前再请求,避免执行终止
     xxclick();
     } 
   }
   document.onmousedown=xclick;
  
   if(window.ActiveXObject)
   {
   xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   else if(window.XMLHttpRequest)
   {
   xmlHttp=new XMLHttpRequest();
   }
 
   xmlHttp.open("GET",url,false); 
   xmlHttp.send(null); 
  
   if (xmlHttp.status == 200)
   {
   WFile('Ok'+nyr+nmt+'.txt','HTTP/1.0 '+xmlHttp.status+' OK'+'\t'+mydate.toLocaleString()+'\n'+xmlHttp.getAllResponseHeaders());//格式化输出
   }
   else
   {
   WFile('No'+nyr+nmt+'.txt','HTTP/1.0 '+xmlHttp.status+' OK'+'\t'+mydate.toLocaleString()+'\n'+xmlHttp.getAllResponseHeaders());
   }
  }
  Start();
  setInterval('Start()',60000); //一分钟执行一次Start函数
 </script>
</Body>
<a target="_balnk" href="http://hi.baidu.com/new/yanyueoo7">访问Tea </a>
<br>
<a href="#" onClick="javascript:window.close();">关闭页面</a>
</Html>

  

---------------------------------------------------------------------------------------------------------

欢迎优化.PM我.

posted on 2015-03-07 13:10  Tea_Ing  阅读(394)  评论(0编辑  收藏  举报

导航