利用XMLHTTP檢測URL及探測服務器信息
阿新 • • 發佈:2018-09-30
gb2 NPU 探測 http服務 innerhtml 不存在 網絡 end 網絡連接
<html> <head> <title>利用XMLHTTP檢測URL及探測服務器信息</title> <META http-equiv=Content-Type content="text/html; charset=gb2312"> <meta name="Generator" content="EditPlus"> <meta name="Author" content="JnKc"> <meta name="Keywords" content=""> </head> <body> <input type="hidden" id="jnkcInput1" value="http://baidu1.com"> <input type="hidden" id="jnkcInput2" value="http://baidu2.com"> <input type="hidden" id="jnkcInput3" value="http://baidu3.com"> <input type="hidden" id="jnkcInput4" value="http://baidu4.com"> <button id="chk">檢測</button> <div id="jnkc_show"></div> <SCRIPT LANGUAGE="VBScript"> Function chk_onClick() Call Hahaha End Function Dim i,g,jnkcUrl,jnkcHTML,jnkcStatus,jnkcServer Sub Hahaha g=1 for g=1 to 4 ‘jnkcUrl = ("jnkcInput"&g).value jnkcUrl = document.getElementById("jnkcInput"&g).value Call GetDetail i= i+1 jnkc_show.innerHTML = "<pre><font color=red>" & i & "、" & jnkcUrl & "</font>" & jnkcStatus & "</pre>" & jnkc_show.innerHTML next End Sub Dim jnkcXMLHTTP Sub GetDetail Set jnkcXMLHTTP = CreateObject("Microsoft.XMLHTTP") jnkcXMLHTTP.OnReadyStateChange = GetRef("GetStatus") jnkcXMLHTTP.Open "GET", jnkcUrl, False On Error Resume Next jnkcXMLHTTP.Send Set jnkcXMLHTTP = Nothing End Sub Sub GetStatus If jnkcXMLHTTP.ReadyState <> 4 Then Exit Sub End If If jnkcXMLHTTP.Status = 404 Then jnkcStatus = "該網頁不存在!" ElseIf jnkcXMLHTTP.Status < 200 Then jnkcStatus = "客戶端錯誤,信息:" & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText ElseIf jnkcXMLHTTP.Status < 300 Then jnkcStatus = "成功,該網頁能訪問。" ElseIf jnkcXMLHTTP.Status < 400 Then jnkcStatus = "重定向,信息:" & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText ElseIf jnkcXMLHTTP.Status < 500 Then jnkcStatus = "客戶端錯誤,信息:" & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText ElseIf jnkcXMLHTTP.Status < 600 Then jnkcStatus = "服務器錯誤,信息:" & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText Else jnkcStatus = "域名不可用或網絡連接錯誤,信息:" & CStr(jnkcXMLHTTP.Status) & " " & jnkcXMLHTTP.StatusText End If ‘If jnkcXMLHTTP.Status < 600 Then Call GetServer End Sub Sub GetServer jnkcServer = jnkcXMLHTTP.GetResponseHeader("Server") If jnkcServer <> "" Then jnkcStatus = jnkcStatus & "<br>HTTP服務器:" & jnkcServer End If jnkcStatus = "<b>" & jnkcStatus & "</b><br>所有反饋信息:<br>"& jnkcXMLHTTP.GetAllResponseHeaders End Sub </SCRIPT> </body> </html>
利用XMLHTTP檢測URL及探測服務器信息