在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 href='http://blog.csdn.net/cqq' 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
%>
當然,我們也可以自己編寫對應的元件或是使用一些現成的元件來實現這樣的功能,
這裡就不多說了。