明輝手游網(wǎng)中心:是一個(gè)免費(fèi)提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺(tái)!

在ASP中執(zhí)行Ping命令,并且返回結(jié)果

[摘要]在Win2000系統(tǒng)中,可以通過Wscript.Shell對(duì)象的Exec方法執(zhí)行命令,簡(jiǎn)單的代碼如下:<% Response.Buffer = true %> <% url = "www.topronet.com" Set objWShell...

在Win2000系統(tǒng)中,可以通過Wscript.Shell對(duì)象的Exec方法執(zhí)行命令,

簡(jiǎn)單的代碼如下:

<% 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 & " 狀態(tài)為: " & strStatus
    response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
    response.write "<br><hr>慈勤強(qiáng)編寫,歡迎訪問<a

target='_blank'>http://blog.csdn.net/cqq</a>"
%>

 

在XP系統(tǒng)或者Windows.NET Server系統(tǒng)中,可以使用WMI來(lái)實(shí)現(xiàn),

代碼如下:

<%
    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 & " 狀態(tài) "
    For Each result in PingResult
        if clng(result.StatusCode)>0 then
            response.write "離線"
        else
            response.write "在線"
        end if
    Next
%>


當(dāng)然,我們也可以自己編寫相應(yīng)的組件或者使用一些現(xiàn)成的組件來(lái)實(shí)現(xiàn)這樣的功能,

這里就不多說了。