问题
I need to know how to get average reply time from using ping command in the vbs.
I found out that I can get all ping output just executing this command but may be I can just get my time data and calculate in variable without using string handling.
Set objExec = objShell.Exec("ping -n 2 -w 1000 " & strTarget)
strPingResults = LCase(objExec.StdOut.ReadAll)
回答1:
I would not recommend shelling out to ping.exe
and then parsing the output. Use WMI instead:
target = 'somecomputer'
n = 2
Set wmi = GetObject("winmgmts://./root/cimv2")
qry = "SELECT * FROM Win32_PingStatus WHERE address='" & target & "'"
rspTime = 0
cnt = 0
For i = 1 To n
For Each pingStatus In wmi.ExecQuery(qry)
If Not IsNull(pingStatus.StatusCode) Or pingStatus.StatusCode = 0 Then
rspTime = rspTime + pingStatus.ResponseTime
cnt = cnt + 1
End If
Next
Next
If cnt > 0 Then
WScript.Echo "Average response time: " & (rspTime / cnt)
Else
WScript.Echo "Host unreachable"
End If
来源:https://stackoverflow.com/questions/58812916/how-to-get-average-reply-time-from-ping-command