Option Explicit
dim objshell, objExec4
Set objShell = WScript.CreateObject("WScript.Shell")
Const sDataFile = "x:\tt\hosts1.txt"
Const ForReading = 1
Const ForWriting = 2
Dim arrIP(), arrName(), arrStatus()
Dim x, c, p, s
ReadData
Dim sThisStatus
For x = LBound(arrIP) To UBound(arrIP)
'Check the ping status of arrIP(x)
p = 0
For c = 0 to 3
If Ping(arrIP(x)) = True Then
p = p + 1
End If
Next
If p >= 2 then
sThisStatus = "UP"
Else
sThisStatus = "DOWN"
End If
If LCase(sThisStatus) <> LCase(arrStatus(x)) Then
objExec4=objShell.run("D:\Temp\SMTPSend.exe -fvalentin.mihul@mozzartbet.com -tvalentin.mihul@mozzartbet.com -sHost_" & arrName(x) & "_is_" & arrStatus(x) & " -hmail.mozzartbet.com",1,True)
End If
arrStatus(x) = sThisStatus
Next
SaveData
Sub ReadData()
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(sDataFile, ForReading)
Dim i, sThisLine, arrThisLine
i = 0
Do Until objFile.AtEndOfStream
sThisLine = objFile.ReadLine 'Get the next line
'split the array, so we can extract the 3 fields
arrThisLine = Split(sThisLine, " ")
'redim the arrays that will hold the different fields
ReDim Preserve arrIP(i), arrName(i), arrStatus(i)
'store the 3 fields for record "i"
arrIP(i) = arrThisLine(0)
arrName(i) = arrThisLine(1)
arrStatus(i) = arrThisLine(2)
i = i + 1
Loop
objFile.Close
End Sub
Sub SaveData()
Dim objFSO, objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim sOutputFile, x
For x = LBound(arrIP) To UBound(arrIP)
sOutputFile = sOutputFile & arrIP(x) & " " & arrName(x) & " " & arrStatus(x) & vbCrLf
Next
Set objFile = objFSO.OpenTextFile(sDataFile, ForWriting, True)
objFile.Write sOutputFile
objFile.Close
End Sub
Function Ping(strHost)
dim objPing, objRetStatus
set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecQuery _
("select * from Win32_PingStatus where address = '" & strHost & "'")
for each objRetStatus in objPing
if IsNull(objRetStatus.StatusCode) or objRetStatus.StatusCode<>0 then
Ping = False
'WScript.Echo "Status code is " & objRetStatus.StatusCode
else
Ping = True
'Wscript.Echo "Bytes = " & vbTab & objRetStatus.BufferSize
'Wscript.Echo "Time (ms) = " & vbTab & objRetStatus.ResponseTime
'Wscript.Echo "TTL (s) = " & vbTab & objRetStatus.ResponseTimeToLive
end if
next
End Function