在Win2000系統中,可以通過Wscript.Shell對象的Exec方法執行命令, 簡單的代碼如下: <% Response.Buffer = true %> <% url = "www.topronet.com" Set objWShell = CreateObject("WScript.Shell") Set objCmd = objWShell.Exec("ping " & url) strPResult = objCmd.StdOut.Readall() set objCmd = nothing: Set objWShell = nothing strStatus = "離線" if InStr(strPResult,"TTL=")>0 then strStatus = "在線" response.write url & " 狀態為: " & strStatus response.write ".<br>" & replace(strPResult,vbCrLf,"<br>") response.write "<br><hr>慈勤強編寫,歡迎訪問<a target='_blank'>http://blog.csdn.net/cqq</a>" %> 在XP系統或者Windows.NET Server系統中,可以使用WMI來實現, 代碼如下: <% url = "www.topronet.com" WMI = "winmgmts:{impersonationLevel=impersonate}" wqlQuery = "SELECT StatusCode FROM Win32_PingStatus WHERE Address" & _ " = '" & url & "'" set PingResult = GetObject(WMI).ExecQuery(wqlQuery, "WQL", 48) Response.write url & " 狀態 " For Each result in PingResult if clng(result.StatusCode)>0 then response.write "離線" else response.write "在線" end if Next %> 當然,我們也可以自己編寫相應的組件或者使用一些現成的組件來實現這樣的功能,
這里就不多說了。
|