Le code ci-dessous est en premier lieu tiré de WMICodeCreator à qui j'ai demandé d'exploiter la classe Win32_PingStatus
Puis j'ai ajouté la partie qui permet de préciser l'adresse Ip à tester.
Option Explicit
Dim objWMIService, strComputer, varNetworkAddress, objItem, colItems
strComputer = "."
varNetworkAddress = "192.168.0.64"
varNetworkAddress = InputBox("Adresse Ip à tester","Adresse cible", varNetworkAddress)
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & varNetworkAddress & + "'",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_PingStatus instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Address: " & objItem.Address
Wscript.Echo "ResponseTime: " & objItem.ResponseTime
Wscript.Echo "ResponseTimeToLive: " & objItem.ResponseTimeToLive
Wscript.Echo "BufferSize: " & objItem.BufferSize
Wscript.Echo "NoFragmentation: " & objItem.NoFragmentation
Wscript.Echo "PrimaryAddressResolutionStatus: " & objItem.PrimaryAddressResolutionStatus
Wscript.Echo "ProtocolAddress: " & objItem.ProtocolAddress
Wscript.Echo "ProtocolAddressResolved: " & objItem.ProtocolAddressResolved
Wscript.Echo "RecordRoute: " & objItem.RecordRoute
Wscript.Echo "ReplyInconsistency: " & objItem.ReplyInconsistency
Wscript.Echo "ReplySize: " & objItem.ReplySize
Wscript.Echo "ResolveAddressNames: " & objItem.ResolveAddressNames
If isNull(objItem.RouteRecord) Then
Wscript.Echo "RouteRecord: "
Else
Wscript.Echo "RouteRecord: " & Join(objItem.RouteRecord, ",")
End If
If isNull(objItem.RouteRecordResolved) Then
Wscript.Echo "RouteRecordResolved: "
Else
Wscript.Echo "RouteRecordResolved: " & Join(objItem.RouteRecordResolved, ",")
End If
Wscript.Echo "SourceRoute: " & objItem.SourceRoute
Wscript.Echo "SourceRouteType: " & objItem.SourceRouteType
Wscript.Echo "StatusCode: " & objItem.StatusCode
Wscript.Echo "Timeout: " & objItem.Timeout
If isNull(objItem.TimeStampRecord) Then
Wscript.Echo "TimeStampRecord: "
Else
Wscript.Echo "TimeStampRecord: " & Join(objItem.TimeStampRecord, ",")
End If
If isNull(objItem.TimeStampRecordAddress) Then
Wscript.Echo "TimeStampRecordAddress: "
Else
Wscript.Echo "TimeStampRecordAddress: " & Join(objItem.TimeStampRecordAddress, ",")
End If
If isNull(objItem.TimeStampRecordAddressResolved) Then
Wscript.Echo "TimeStampRecordAddressResolved: "
Else
Wscript.Echo "TimeStampRecordAddressResolved: " & Join(objItem.TimeStampRecordAddressResolved, ",")
End If
Wscript.Echo "TimestampRoute: " & objItem.TimestampRoute
Wscript.Echo "TimeToLive: " & objItem.TimeToLive
Wscript.Echo "TypeofService: " & objItem.TypeofService
Next
Lien vers le fichier : cliquez ici
Ci-dessous une variante où l'on va pinguer une adresse ip toutes les 5 secondes puis ont relève la latence et on log les résultats dans un fichier.
Option Explicit
Dim objFSO, objTextFile
Dim NomFichier, CheminFichier, CheminScriptActuel, ScriptFileName, Position
Dim objWMIService, strComputer, varNetworkAddress, objItem, colItems
'Déclaration des constantes
Const ForReading = 1
Const ForWritting = 2
Const ForAppending = 8
ScriptFileName = wscript.scriptname
Position = InstrRev(ScriptFileName,".")
if (Position > 0) Then ScriptFileName = Left(ScriptFileName, Position - 1)
NomFichier = ScriptFileName & "_Resultat.txt"
CheminScriptActuel = Left(wscript.scriptfullname,Len(wscript.scriptfullname)-Len(wscript.scriptname)-1)
CheminFichier = CheminScriptActuel & "\" & NomFichier 'Déclaration du chemin et du nom du fichier
If Len(CheminFichier) > 0 Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(CheminFichier, ForWritting, True)
objTextFile.WriteLine(Now) 'On ecrit la date et l'heure dans le fichier
strComputer = "."
varNetworkAddress = "192.168.202.64"
varNetworkAddress = InputBox("Adresse Ip à tester","Adresse cible", varNetworkAddress)
objTextFile.WriteLine("Date/Heure" & VbTab & "Address" & VbTab & "ResponseTime")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Do
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_PingStatus where address = '" & varNetworkAddress & + "'",,48)
For Each objItem in colItems
objTextFile.WriteLine(Now & VbTab & objItem.Address & VbTab & objItem.ResponseTime)
Next
Set colItems = Nothing
WScript.Sleep(5000)
Loop While 1 > 0
objTextFile.Close 'Fermeture du fichier
Set objTextFile = Nothing
Set objFSO = Nothing
Else
Wscript.echo "Operation annulee"
End If 'CheminFichier
Lien vers le fichier : cliquez ici
Pages Web
Site Web | Description |
---|---|
Hey, Scripting Guy! Blog | Article des Scripting Guy! sur la question |
Article(s) en relation(s)