Solved Use VBS and Batch to calculate average ping

Hewlett-packard / Pavilion hpe
March 9, 2015 at 14:35:47
Specs: Windows 7 Professional x64, 3.6GHz 16GB
I have a batch script I'm making and I need the functionality to make it calculate average latency (say average latency of 5 pings). I know this isn't possible to do purely in batch, but I know it is doable by passing arguments to a vbscript file. However I have no idea on how to format the arguments and how to write such a file.

Would anyone by chance know how to do this?

If infinity is infinite, is the square root of infinity infinite as well?
- Kurp Von Steiner

See More: Use VBS and Batch to calculate average ping

Report •

March 9, 2015 at 16:34:05
Consider the following VBScript:
Set wmi = GetObject("winmgmts:")
For i = 1 to 4
  Set ping = wmi.Get("Win32_PingStatus.Address=''")
  If Not (IsNull(ping.StatusCode) Or ping.StatusCode) Then
    total = total + ping.ResponseTime
    WScript.Echo "Ping Failed, #" & i & " of 4"
  End If
Next 'i
WScript.Echo total / 4

How To Ask Questions The Smart Way

Report •

March 10, 2015 at 23:16:15
✔ Best Answer
::====== script starts here ===============
:: pingavg.bat 2015-03-10 21:00:30.04
@echo off & setLocal enableDELAYedeXpansioN

set SUM=
set N=
for /f "tokens=5 delims= " %%a in ('ping ^| find "Reply"') do (
set/a N+=1
set T=%%a
set T=!T:~0,-2!
set T=!T:~5!
set/a SUM+=T*1000
set/a A=SUM/N/1000
goto :eof
::====== script ends here =================


M2 Get custom script or take private lessons

Report •
Related Solutions

Ask Question