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

ASP
保护 XML Web 服务免受黑客攻击
开发BtoC电子商务系统(ASP.NET)
用asp.net实现的把本文推荐给好友功能
尝尝ASP.NET中的小甜饼
web.config一个中文解释
使用ASP.NET加密口令
在SQL Server中保存和输出图片
ASP 中健壮的页结构的异常处理
如何使你的机器运行ASP?
asp(Active Server Page)的语言特性
关于inc文件
IE4 的 模 式 对 话 框 设 计
亲密接触ASP.net(6)
亲密接触ASP.Net(7)
用ASP.Net写一个发送ICQ信息的程序
用ASP.Net编写的查询域名的程序
使用 ASP+ 列表绑定控件(上)
使用 ASP+ 列表绑定控件(中)
使用 ASP+ 列表绑定控件(下)
揭开ASP神秘面纱(1)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 67 ::
收藏到网摘: 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
%>


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

这里就不多说了。