Use WSH to call the system Ping command, redirect the Ping result to a text file, and then display the text file to the webpage. The specific procedure is as follows:
First, create a. BAT file (for example, myPing. BAT :), which must be called in ASP. The file code is as follows:
Ping-a % 1> d: \ INetPub \ cgi-bin \ pai2.txt
(% 1) is the address to be pinged in the future, and (% 2) is the file storing the ping result. The following is the ASP code:
<%
Set FileSys = Server. CreateObject ("Scripting. FileSystemObject ")
FileName = FileSys. GetTempName
Set WShShell = Server. CreateObject ("WScript. Shell ")
IP = "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"
%>