找回密码
 注册
搜索
热搜: 回贴

在ASP中执行Ping命令,并且返回结果

2009-12-13 13:47| 发布者: admin| 查看: 82| 评论: 0|原作者: 段誉

〖在Win2000系统中,可以通过Wscr......


  在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 ".
" & replace(strPResult,vbCrLf,"
")
response.write "

慈勤强编写,欢迎访问target='_blank'>http://blog.csdn.net/cqq"
%>

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

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

最新评论

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 23:25 , Processed in 0.217165 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部