Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ping 2

Status
Not open for further replies.

muggle

Technical User
Jan 19, 2001
4
US
What is the best way to setup a web page to perform a PING?
 
I came up with this after reading your post... I've never written anything like this before so it was fun :)

There are two files you will need. An ASP file that invokes the ping command via a batch file, and the batch file to execute ping and create a semaphore file when the process is complete.

The last line of the pingit.bat file removes the .fin file. This is necessary because windows buffers output. Your script will see the .fin file as soon as it is created and render the contents of the text file. If the script tries to delete the .fin file it will get a permission denied. Deleting the .fin file in the batch file allows your script to catch the creation of the .fin file, and allows it to be removed cleanly.

C:\temp was a quick workaround. You should create a secure directory inside your web root for your output and use that.

'pingit.bat

@echo off
ping -n 10 %1 > c:\temp\%1.txt
echo DONE > c:\temp\%1.fin
del c:\temp\%1.fin

'Ping .asp
Code:
<%
ip = request(&quot;ip&quot;)
set shell = server.createobject(&quot;wscript.shell&quot;)
shell.Run(&quot;pingit &quot; & ip)
set FSO = server.createobject(&quot;scripting.filesystemobject&quot;)

'Check for the semaphore
do until fso.fileExists(&quot;c:\temp\&quot; & ip & &quot;.fin&quot;)

loop

Set TextStream = FSO.OpenTextFile(&quot;c:\temp\&quot; & ip & &quot;.txt&quot;, 1)
S = TextStream.ReadAll & NewLine & NewLine
TextStream.Close

'Cleanup
FSO.DeleteFile(&quot;c:\temp&quot; & ip & &quot;.txt&quot;)

set FSO=nothing
set shell=nothing

response.write &quot;<PRE>&quot; & S & &quot;</PRE>&quot;
 
Note you can just as easily do a traceroute by replacing the ping command in pingit.bat with &quot;tracert&quot; (minus the quotes of course) instead of &quot;ping -n&quot;

Oh, that was the other thing.. -n tell ping how many times to ping the destination computer.

I chose -n 10 because it gives a nice average.
 
Yes, it did. I owe you a great big thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top