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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logging pings

Status
Not open for further replies.

flea333

Technical User
Sep 4, 2003
47
US
I want to repeatedly ping a computer and log when I no longer can ping them. So I need to record the last time it was able to ping the computer.
 
Something like (pseudo-code)
ping a computer
if %ERRORLEVEL% neq "0" Then Echo Date time > Log.txt

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
try this, and set it up as a scheduled task to run every few minutes or whenever:


'=======================================================
' Name: ping.vbs
' Date: 10/02/05
' Fersiwn: 1.1
'------------------------------------------------------
' Change these:
ipcheck="tempfile="c:\pingtemp.txt"
logfile="c:\ping.txt"

'=======================================================

Set wshShell=WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

wshShell.run "cmd /c ping -n 2 -w 20000 " & ipcheck & " > " & tempfile, 0, True

Set tempfile = fso.GetFile(tempfile)
Set ts = tempfile.OpenAsTextStream(1)
strResponse = "Nid yw'ch cyfrifiadur yn gweld y gweinydd."
gweldgweinydd="false"
Do Until ts.AtEndOfStream = True
If InStr(ts.ReadLine, "Reply") > 0 Then
strResponse = Now()
pingcomplete="true"
Exit Do
End If
Loop
ts.Close

if pingcomplete="true" then
Set logtxt = fso_OpenTextFile(logfile, ForAppending, True)
logtxt.WriteLine(strResponse)
logtxt.Close
end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top