Use WSH to invoke the ping command of the system, redirect the result of the ping to a text file, and then display the text file to the Web page as follows:
First, build one. BAT file (for example: Myping.bat:), this file is to be called in ASP, the file code is as follows:
Ping-a%1 > D:\INetPub\cgi-bin\%2.txt
(% 1) is the address to ping in the future, (% 2) is the file that stores ping results. The following is the code for 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("
")
else
Response.Write(Mid(TextBuffer,i,1))
end if
Next
TextFile.Close
FileSys.DeleteFile "d:\Inetpub\cgi-bin\" & FileName & ".txt"
% >