How to implement ping in ASP

zhaozj2021-02-11  239

How to implement ping in ASP

Use the WSH call to call the system's ping command, redirectize the result of the ping to a text file, then display the text file to the web page.

The specific practices are as follows: First, build a .bat file (for example: myping.bat :), this file wants to call in the 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 a file that stores ping results. The following is the code of the ASP:

<% Set filesys = server.createObject ("scripting.filesystemObject") filename = filesys.gettempname

SET WSHSHELL = Server.createObject ("wscript.shell")

IP = "xxx.xxx.xxx.xxx" 'You want ping address Retcode = wshshell.run ("D: /inetpub/cgi-bin/myping.bat" & IP & "& FileName, 1, true)

if Retcode = 0 THEN 'No error Elseresponse.Redirect "pingerrors.htm" endiff

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"

%>

转载请注明原文地址:https://www.9cbs.com/read-4152.html

New Post(0)