1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
| Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim ficMachines, ficHistorique
ficMachines = "D:\Liste_Machines.txt"
ficHistorique = "D:\Histo_Ping.txt"
Set WshShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FileExists(ficHistorique) Then
Set ficHistorique_op = objFSO.OpenTextFile(ficHistorique, ForWriting, True)
ficHistorique_op.WriteLine ""
Set ficHistorique_op = Nothing
End If
Set ficMachines_op = objFSO.OpenTextFile(ficMachines, ForReading, True)
Do While ficMachines_op.AtEndOfStream <> True
Machine = Trim(ficMachines_op.ReadLine)
MachineLen = Len(Machine)
Set WshExec = WshShell.Exec("ping -n 1 -w 200 " & Machine)
PingResult = LCase(WshExec.StdOut.ReadAll)
Set WshExec = Nothing
'Wscript.Echo PingResult,,"PingResult"
PingState = "NOK"
If InStr(PingResult, "octets=") Then PingState = "OK"
Trouve = False
Ligne = ""
ficHistorique_str = ""
Set ficHistorique_op = objFSO.OpenTextFile(ficHistorique, ForReading, True)
Do While ficHistorique_op.AtEndOfStream <> True
Ligne = ficHistorique_op.ReadLine
LigneLeft = Left(Ligne, MachineLen)
If LigneLeft = Machine Then
Trouve = True
'Wscript.Echo Ligne, , "Ligne"
'Wscript.Echo Machine, , "Machine"
ficHistorique_str = ficHistorique_str & Ligne & " --> " & PingState & vbCRLF
ElseIf Ligne <> "" Then
ficHistorique_str = ficHistorique_str & Ligne & vbCRLF
End If
Loop
Set ficHistorique_op = Nothing
If Trouve = False Then ficHistorique_str = ficHistorique_str & Machine & " " & PingState
'Remplacement du contenu historié
'Wscript.Echo ficHistorique_str, , "ficHistorique_str"
objFSO.DeleteFile(ficHistorique)
Set ficHistorique_op = objFSO.OpenTextFile(ficHistorique, ForWriting, True)
ficHistorique_op.WriteLine ficHistorique_str
Set ficHistorique_op = Nothing
Loop
Set ficMachines_op = Nothing
Set objFSO = Nothing
Set WshShell = Nothing |
Partager