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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
' Variables et constantes
Option Explicit
'On Error Resume Next
Dim strAdrATester, Result, i, oFsoLog, oLog, strFileTrend, oFileTrend
' A convertir en fonction ou procedure
Dim oFsoTrendParam, oTrendParam, strLigneLue, strNonMaj
Const PARAMRECHERCHE = "10.22.10.19"
Const STRPLAGEIP = "10.22.12." 'Plage d'ardesse à tester de 0 à 255
Const FICHIERLOG = "C:\install\log.csv"
Const FORREAD=1
Const FORWRIT=2
Const FORAPPEND=8
Const FICHIERTREND="\C$\Program Files\Trend Micro\OfficeScan Client\OFCSCAN.INI"
'==========================================================================
'Déclaration des objets
''Ouverture (création si absent) du fichier "FICHIERLOG"
Set oFsoLog = CreateObject("Scripting.FileSystemObject")
Set oLog = oFsoLog.OpenTextFile(FICHIERLOG, FORAPPEND, True)
Set oFileTrend=CreateObject("Scripting.FileSystemObject")
'==========================================================================
' Corps du programme
For i = 6 To 8 Step 1
strAdrATester = STRPLAGEIP & i
Result = TestAdrIp(StrAdrATester)
If Result = "present" Then
'Verif si trend installé
strFileTrend="\\" & strAdrATester & FICHIERTREND
'WScript.Echo strFileTrend
' Tester le IF
strNonMaj = 0
if oFileTrend.FileExists(strFileTrend) Then
WScript.Echo "le fichier existe"
Set oFsoTrendParam = CreateObject("Scripting.FileSystemObject")
Set oTrendParam = oFsoTrendParam.OpenTextFile(strFileTrend, FORREAD, True)
Do Until oTrendParam.atendofstream
strLigneLue = oTrendParam.readline()
'WScript.Echo strLigneLue
If InStr(1, strLigneLue, PARAMRECHERCHE) > 0 Then
WScript.Echo strAdrATester & "Poste à jour"
'maj Log : Etat = Poste à jour; Date = now()
strNonMaj = 1
Exit Do
End If
Loop
If strNonMaj = 0 Then
WScript.Echo strAdrATester & "PSEXEC lancé"
'maj log : Etat = MAJ lancée; Date = now()
'PSEXEC
End If
oTrendParam.Close
Set oTrendParam = Nothing
Set oFsoTrendParam = Nothing
Else
WScript.Echo strAdrATester & "Anti-virus non-installé sur le poste"
'maj log : Etat = Anti-virus non-installé sur le poste
End If
Else
WScript.Echo "Poste éteint ou absent"
End If
'Ajout des valeurs "strAdrATester" et "Result" séparées par un ; dans "FICHIERLOG"
oLog.WriteLine( strAdrATester & ";" & Result)
Next
oLog.close
'==========================================================================
' Fonctions et procédures
' Fonction qui reçoit une adresse IP et renvoie present si le poste est présent sur le réseau
' ou absent s'il n'y a pas de réponse au ping
Function TestAdrIp(strIpCible)
On Error Resume Next
Const WaitOnReturn = TRUE 'on attend la fin de l'exécution
Const WindowStyle = 0 'on n'ouvre pas de fenêtre
Dim oShell, oExec, strPingResults
Set oShell = CreateObject("WScript.Shell")
Set oExec = oShell.Exec("ping -n 1 -w 1000 " & strIpCible)
strPingResults = LCase(oExec.StdOut.ReadAll)
If InStr(strPingResults, "ponse de " & strIpCible) Then
TestAdrIp = "present"
Else
TestAdrIp = "absent"
End If
End Function
wscript.quit 0 |
Partager