在ASP中執(zhí)行Ping命令,并且返回結(jié)果
發(fā)表時(shí)間:2024-02-02 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]在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)這樣的功能,
這里就不多說了。