如何在ASP中实现PING

如何在ASP中实现PING

使用WSH调用系统的Ping命令,将Ping的结果重定向到一个文本文件中去,再把文本文件显示到网页中

具体做法如下:
首先, 建一个.BAT文件(例如:myPing.BAT:),这个文件要在ASP中调用,文件代码如下:
ping -a %1 > d:/INetPub/cgi-bin/%2.txt
(%1)是将来要ping的地址, (%2)是存储ping结果的文件. 以下是ASP的代码:

<%
Set FileSys = Server.CreateObject("Scripting.FileSystemObject")
FileName = FileSys.GetTempName

Set WShShell = Server.CreateObject("WScript.Shell")

IP = "xxx.xxx.xxx.xxx" '你要ping的地址
RetCode = WShShell.Run("d:/Inetpub/cgi-bin/myPing.bat " & IP & " " & FileName, 1, True)

if RetCode = 0 Then
'没有错误
else
Response.Redirect "PingErrors.htm"
end if

Set TextFile = FileSys.OpenTextFile("d:/InetPub/cgi-bin/" & FileName & ".txt", 1)
TextBuffer = TextFile.ReadAll

For i = 1 to Len(TextBuffer)

If Mid(TextBuffer,i,1) = chr(13) Then

Response.Write("<BR>")

else

Response.Write(Mid(TextBuffer,i,1))

end if

Next

TextFile.Close

FileSys.DeleteFile "d:/Inetpub/cgi-bin/" & FileName & ".txt"

%>


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值