以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 Dot NET,C#,ASP,VB 』  (http://bbs.xml.org.cn/list.asp?boardid=43)
----  [转帖]在ASP中执行Ping命令,并且返回结果  (http://bbs.xml.org.cn/dispbbs.asp?boardid=43&rootid=&id=14726)


--  作者:Qr
--  发布时间:2/23/2005 3:36:00 PM

--  [转帖]在ASP中执行Ping命令,并且返回结果
在ASP中执行Ping命令,并且返回结果


在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
%>


当然,我们也可以自己编写相应的组件或者使用一些现成的组件来实现这样的功能,

这里就不多说了。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
421.875ms