Use WSH to call the system's Ping command, redirect the Ping result to a text file, and then display the text file on the web page. The specific method is as follows:
First, create a .BAT file (for example: myPing.BAT:). This file should be called in ASP. The file code is as follows:
ping -a %1 > d:/INetPub/cgi-bin/%2.txt
(%1) is the address to be pinged in the future, (%2) is the file that stores the ping results. The following is the code of ASP:
<%
Set FileSys = Server.CreateObject(Scripting.FileSystemObject)
FileName = FileSys.GetTempName
Set WShShell = Server.CreateObject(WScript.Shell)
IP = xxx.xxx.xxx.xxx 'The address you want to ping
RetCode = WShShell.Run(d:/Inetpub/cgi-bin/myPing.bat & IP & & FileName, 1, True)
if RetCode = 0 Then
'no error
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
%>