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 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191
| '*****************
'SCRIPT 4nthon
'*****************
'******************************************************************************'
'* * * ANTHONY B. 4nthon - SCRIPT RECUP LECTEURS RESEAUX * * *
'* 03-08-2013
'******************************************************************************'
'---Erreurs en mode "manuel"
On Error Resume Next
'**********************************
' DECLARATIONS
Dim oct1
dim oct2
dim oct3
dim oct4
dim adresseIP
Dim ping
dim nsl00kup
dim strComputer
dim strName
Dim alphabet
'**********************************
'**********************************
'Document sortie de texte
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objTextFile_ipNOK = objFSO.CreateTextFile("XXX-NO.parc_INFRA_wmi.txt")
Set objTextFile_ipOK = objFSO.CreateTextFile("YYY-ON.parcINFRA_rsx_wmi.txt")
'Objets
Set objNetwork = WScript.CreateObject("WScript.Network")
Set colDrives = objNetwork.EnumNetworkDrives
Set Hdd_computer = objFSO.Drives
' Pour voir les disques internes
'Set wshShell = WScript.CreateObject( "WScript.Shell" ) 'fonctionne pour "nom_pc"
' Pour les Tests Ping & Nslookup
'**********************************
'Set locale "set en CMD"
'Ne fonctionne que pour le local / machine executant la commande
'nom_pc = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
'nom_user = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
'nom_cls = wshShell.ExpandEnvironmentStrings( "cls" )
'**********************************
' Valeur des variables (défaut à 0) :
oct1 = 0
oct2 = 0
oct3 = 0
oct4 = 0
'concaIP = oct1 & "." & oct2 & "." & oct3 & "." & oct4
'**********************************
'**********************************
'alphabet as string
alphabet = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z"
pingo = "perdus = 0"
'**********************************
test_ping2 = booleen
'**********************************
' Lexique :
' concaIP : Concaténation IP
' oct[x] : octet de chaque tronceau d'IP
'
'Aide : for est équivalent à {
'Aide : next est équivalent à }
' vbCrLf = Permet de faire un retour à la ligne
' xxxxx.Write (pour écrire sur une ligne)
' xxxxx.WriteLine (pour sauter une ligne à chaque instruction)
'**********************************
' Déclaration des lignes (tableau excel)
' Ping OK
objTextFile_ipOK.Write("IP ORDINATEUR" & ";" & "PING" & ";" & "NOM MACHINE" & ";" & "NOM UTILISATEUR" & ";" & "DOMAINE" & ";" & "LETTRE" & ";" & "CHEMIN RSX" & ";" & "NSLOOKUP" & vbCrLf & vbCrLf)
' Ping NOK (garder un historique)
objTextFile_ipNOK.Write("IP ORDINATEUR" & ";" & "PING" & ";" & "NSLOOKUP" & vbCrLf & vbCrLf)
'msgbox (alphabet)
'Début des boucles pour les octets 1 à 4
'********************************** DEBUT DU SCRIPT
' Mise en place des octets
For oct1 = 192 To 192
For oct2 = 168 To 168
For oct3 = 44 To 44
For oct4 = 100 To 110
concaIP = oct1 & "." & oct2 & "." & oct3 & "." & oct4
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & concaIP & "\root\cimv2")
Set colCompSystems = objWMIService.ExecQuery("SELECT * FROM " & "Win32_ComputerSystem")
Set test_1 = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & concaIP & "'") 'test ping 1 (ulterieur xp)
Set oo = GetObject("winmgmts:{impersonationLevel=impersonate}!\\").ExecQuery("select * from Win32_PingStatus where address = '" & concaIP & "'") ' SET ping 2 (win 2000, Xp)
Set test_2 = objShell.Exec("ping -n 2 -w 1000 " & concaIP) 'test ping 2 (win2000)
Set test_3 = objShell.Exec("nslookup " & concaIP) 'test nslookup
Set nsloo = objShell.Exec( "nslookup " & concaIP)
'**********************************
' SET : information utilisateur
Set user_sys = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
'**********************************
'********************************** Information
objTextFile_ipOK.Write (concaIP & ";")
objTextFile_ipNOK.Write (concaIP & ";")
'********************************** Test Ping 1 + Requête WMI (information utilisateur)
For Each objStatus in test_1
msgbox objStatus
Set objExec = objShell.Exec("ping -n 4 -w 1000 " & concaIP)
strPingResults = LCase(objExec.StdOut.ReadAll)
If InStr(strPingResults, "perte 0%") Then
'MsgBox concaIP & " responded to ping."
For Each objCompSystem In colCompSystems
objTextFile_ipOK.Write ("Ping OK" & ";")
objTextFile_ipNOK.Write ("Ping OK" & ";")
Next
' (ligne 125)
For Each objItem in user_sys
objTextFile_ipOK.Write (objItem.Name & ";" & objItem.UserName & ";" & objItem.Domain & ";")
Next
' (ligne 130)
Else
objTextFile_ipNOK.Write ("PING NOK" & ";")
End If
'**********************************
' SET : Lecteur réseaux
Set media_uc = objWMIService.ExecQuery("SELECT * FROM Win32_MappedLogicalDisk", "WQL", wbemFlagReturnImmediately + wbemFlagForwardOnly)
'**********************************
'********************************** Test Ping 2 + Requête WMI (lecteurs réseaux)
For Each objStatus_2 in oo
If objStatus_2.Statuscode = 0 Then
For Each objitem in media_uc
objTextFile_ipOK.Write (objitem.Name & ";" & objitem.ProviderName & ";")
Next
' (ligne 146)
Else
objTextFile_ipOK.Write (" *************AUCUNE INFORMATION************* ")
End If
'********************************** Test Nslookup
Set nsl = CreateObject("WScript.Shell")
Set objScript_nsl = objShell.Exec("nslookup " & concaIP)
resultat_nsl = LCase(objScript_nsl.StdOut.ReadAll)
If InStr(resultat_nsl, "nom :") Then
objTextFile_ipOK.Write ("Nslookup OK" & ";")
Else
objTextFile_ipNOK.Write ("Nslookup NOK" & ";")
End If
objTextFile_ipNOK.Write (vbCrLf)
objTextFile_ipOK.Write (vbCrLf)
Next
' (ligne 119)
Next
' (ligne 95)
Next
' (ligne 93)
Next
' (ligne 91)
Next
' (ligne 89)
Next
'********************************** FERMETURE DU FICHIER TEXTE
objTextFile_ipNOK.close
objTextFile_ipok.close
'********************************** FIN DU SCRIPT
WScript.Quit |
Partager