当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在ASP中执行Ping命令,并且返回结果

ASP
用asp怎样编写文档搜索页面(5)
用asp怎样编写文档搜索页面(6)
ASP.NET: XML计数器第二版
ASP.NET: XML留言版第二版
不用图像组件的ASP图像计数器
用ASP实现文档资料管理
用ASP实现号码转换程序实例
如何用SAFileUp上传文件?
jmail4.1用pop3收信的例子
功能非常全面的日期处理函数
一个检查E文拼写错误的Code
简单的加密方法:XOR
ASP连接执行程序
编写“公平”的ASP图形计数器
跟我学做最强功能的网站统计
用asp.net写的论坛程序
用asp.net写的论坛程序--论坛主页
用asp.net写的论坛程序--浏览贴及回复
用asp.net写的论坛程序--上贴保存
利用CDONTS发送邮件的ASP函数

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 82 ::
收藏到网摘: n/a

 

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


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

这里就不多说了。