Hi All, i am using the following script which was posted on this forum
and it works great, one slight problem i have not been able to get
around is how to make it do the ping silently, as it stands now it
keeps flashing a dos box up every few seconds when it does the pings,
i cant seem to get it to run silent, can anyone advise ?
On Error Resume Next
Dim target, cnt, iCnt
Dim iMsg
Dim iConf
Dim Flds
Dim strHTML
Dim objFSO, objCfgFile, arrIp(256), arrName(256), arrStatus(256)
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objCfgFile = objFSO.OpenTextFile("mon.cfg", ForReading)
WScript.Echo "Started at: " & Now
WScript.Echo "Monitoring Device:" & vbCrLf
'read the config file
iCnt = 0
Do While objCfgFile.AtEndOfStream <> True
strLine = objCfgFile.ReadLine
arrCfgRecord = split(strLine, ",")
' arrCfgRecord = Array(strLine) ' should this work too? investigate
some other time...!
arrIp(iCnt) = Trim(arrCfgRecord(0))
arrName(iCnt) = Trim(arrCfgRecord(1))
arrStatus(iCnt) = TRUE ' For now we assume all systems are
responsive
Wscript.Echo "Device :" & Trim(arrCfgRecord(0)) & vbTab & "Name:" &
vbTab & Trim(arrCfgRecord(1))
if (Len(strLine)>1) then ' Skip empty lines in the config file
iCnt = iCnt + 1
End If
Loop
Set objShell = CreateObject("WScript.Shell")
'The real meat: where we poll the systems every 10 seconds
do
wscript.sleep(1000) 'milliseconds
for cnt = 0 To iCnt -1 'do this as often as you found devices in the
config file
strPing = "ping -l 1 -n 3 -w 500 "
Set objExec = objShell.Run (strPing & arrIp(cnt)) 'we try 3 pings with
a 5 second wait.
strPingResults = LCase(objExec.StdOut.ReadAll)
strTestagainst = "reply from " & arrIp(cnt)
' WScript.Echo arrName(cnt) & " " & arrStatus(cnt) 'debug
If InStr(strPingResults, strTestagainst) Then
' If we can ping the system
if (arrStatus(cnt)=FALSE) then ' if the old
status was that the system was down
WScript.Echo Now & vbTab & " " & "System Is Up: " &
arrName(cnt) ' inform user system is back again
end if
'WScript.Echo arrName(cnt) & " responded to ping." 'debug
'Wscript.Echo "--" & strPingResults
'Wscript.Echo "--" & strTestagainst
arrStatus(cnt)=TRUE ' system
respons, so status is up
Else
if (arrStatus(cnt)=TRUE) then ' if status
was up
WScript.Echo Now & vbTab & " " & "System Is Down: " &
arrName(cnt) ' inform user the system is down.
end if
arrStatus(cnt)=FALSE ' system does not
respond, so status is down
End If
Next
loop
' Clean up variables.
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing