用asp獲取ping值,可以通過Wscript.Shell對象的Exec方法執(zhí)行命令,返回結(jié)果。
代碼如下:
<% Response.Buffer = true %>
<%
url = "www.baidu.com"
Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("ping " & url)
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing: Set objWShell = nothing
response.write url
response.write ".<br>" & replace(strPResult,vbCrLf,"<br>")
%>
執(zhí)行結(jié)果
www.baidu.com.
Pinging www.a.shifen.com [121.14.89.14] with 32 bytes of data:
Reply from 121.14.89.14: bytes=32 time=11ms TTL=57
Reply from 121.14.89.14: bytes=32 time=12ms TTL=57
Reply from 121.14.89.14: bytes=32 time=12ms TTL=57
Reply from 121.14.89.14: bytes=32 time=12ms TTL=57
Ping statistics for 121.14.89.14:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 11ms, Maximum = 12ms, Average = 11m