It mainly uses some methods and attributes of XMLHTTP to obtain server information.
The XMLHTTP object method and object attributes are attached to the following documents:
Http://www.csdn.net/Develop/article/16/16493.shtm
For more information about the status code, see my document "Internet HTTP connection and other error codes".
Http://www.csdn.net/Develop/Article/16/16477.shtm
The following are all source code:
<HTML>
<Head>
<Title> Use XMLHTTP to detect websites and server types </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 = "text" id = "jnkcinput" value = "http://www.csdn.net" size = "50"> <button id = "Chk"> detection </button>
<Div id = "jnkc_show"> </div>
<Script language = "VBScript">
Dim I, jnkcurl, jnkchtml, jnkcstatus, jnkcserver
Function chk_onclick ()
Jnkcurl = jnkcinput. Value
Call getdetail
I = I + 1
Jnkc_show.innerhtml = "<HR> <PRE> <font color = Red>" & I & "," & jnkcurl & "</font> <br>" & jnkcstatus & "</ PRE> "& jnkc_show.innerhtml
End Function
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 = "this webpage does not exist! "
Elseif jnkcxmlhttp. Status <200 then
Jnkcstatus = "client error, message:" & CSTR (jnkcxmlhttp. Status) & "& jnkcxmlhttp. statustext
Elseif jnkcxmlhttp. Status <300 then
Jnkcstatus = "successful. This webpage can be accessed. "
Elseif jnkcxmlhttp. Status <400 then
Jnkcstatus = "redirection, information:" & CSTR (jnkcxmlhttp. Status) & "& jnkcxmlhttp. statustext
Elseif jnkcxmlhttp. Status <500 then
Jnkcstatus = "client error, message:" & CSTR (jnkcxmlhttp. Status) & "& jnkcxmlhttp. statustext
Elseif jnkcxmlhttp. Status <600 then
Jnkcstatus = "server error, message:" & CSTR (jnkcxmlhttp. Status) & "& jnkcxmlhttp. statustext
Else
Jnkcstatus = "Domain Name unavailable or network connection error, message:" & 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 server:" & jnkcserver
End if
Jnkcstatus = "<B>" & jnkcstatus & "</B> <br> All feedback: <br>" & jnkcxmlhttp. getAllResponseHeaders
End sub
</SCRIPT>
</Body>
</Html>