How to use ASP to implement ping

zhaozj2021-02-11  224

How to use ASP to implement ping

This article presents a simple way to ping an address and get the results of the ping using ASP. The idea was supplied by Bart Silverstein. First, a .BAT file needs to be created that will be run from the Active Server Page. Let's call This file doping.bat. It will contact. Only One Statement, Which Will Ping a passed in ip address. Here is the code for doping.bat: ping -a% 1> d: /inetpub/cgi-bin/%2.txt This will, if you can't tell, ping the address passed in as the first command line argument (% 1), and redirect the results to a text file named hype second company line argument (% 2). Now, Let's Look how we would call this from an ASP file: <% Set FileSys = Server.CreateObject ( "Scripting.FileSystemObject") FileName = FileSys.GetTempNameSet WShShell = Server.CreateObject ( "WScript.Shell") IP = "204.123.54.1" ' Or whatver you want to pingretcode = wshshell.run ("D: /inetpub/cgi-bin/doping.bat" & IP & "& FileName, 1, True) if retcode = 0 the'therenene no errorselsersponse.redirect" Pinge Rrors.htm "endset textfile = filesys.opentextfile (" D: / inetpub / cgi-bin / "& filename &" .txt ", 1) textBuffer = TextFile.ReadallFor i = 1 to Len (TextBuffer) if Mid (TextBuffer , i, 1) = chr (13) ThenResponse.write ("
") Elseresponse.write (MID (TextBuffer, i, 1)) end ifnexttextfile.closefilesys.deletefile "D: / inetpub / cgi-bin /" & FileName & ".txt"%>

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

New Post(0)