How to Implement PING in ASP

Source: Internet
Author: User

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"
%>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.