-4

I'd like to create a batch file that will automatically output the "Jitter" results to the screen after a ping command.

C:\Ping Google.com

Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56
Reply from 172.217.11.174: bytes=32 time=9ms TTL=56

http://www.3rdechelon.net/jittercalc.asp has a calculator that if one can copy/paste into that square/field the Jitter results appear.

As far as I can determine about "Jitter is the measurement of the difference (Δ time or delta time) between each return message from the Ping."

instead of copy/paste to that website, I want to have it outputted to the screen.

George Gill
  • 43
  • 1
  • 6
  • 1
    I'm not sure why this has so many downvotes (Might be that you provide no source code or attempts & Use this site for free code based on post history) but check bellow as I have a working solution. – John Kens Dec 15 '18 at 01:50

1 Answers1

3

From what I understand using this article, "To measure Jitter, we take the difference between samples, then divide by the number of samples (minus 1).". This means we will have to take the data in array and do a little math on it.

Using there example, These latencies: 136, 184, 115, 148, 125 - We take the first two, subtract them, and do that for all examples down the line to get the difference.

48, 69, 33, 23 will be our differences. From here we need to find the "Mean" of all 4 results. To do this we add them all up them (173) then divide by 4. This is what my script does. Check out all the notes I left in the script.

Jitter.bat

@ECHO OFF
@Setlocal EnableDelayedExpansion

Rem | Configuration
Rem | Address - The Address You Wish To PING
Rem | PingAmount - The Amount Of Times To Ping Each Cycle
set "Address=google.com"
set "PingAmount=10"

:LOOP
Set "SUM1=0"
Set "SUM2=0"
Set "WHOLE=0"
Set "MEAN=0"
Set "RUN=0"
set "MAX=0"
Set "TOTAL=0"

Echo Waiting For Ping Data...

Rem | Change The Ping Command To Strings
FOR /F "tokens=1-4,5,*" %%A in ('Ping -n %PingAmount% "%Address%" ^| Find /I "Reply"') DO (

    Rem | This is optional; Will Display Whole "Ping"
    Echo %%A %%B %%C %%D [%%E] %%F

    Rem | Grab Only "Time="
    FOR /F "tokens=1,* delims==" %%G in ('echo %%E') DO (

        Rem | Edit "Time=" String To Extract Only The Time
        Set "String=%%H"
        Set String=!String:ms=!%

        Rem | Do Math
        IF "!WHOLE!"=="2" (

            Rem | Compare Strings & Sort
            If "!SUM1!"=="!String!" (

                Set "MAX=!Sum1!"
                Set "MIN=!String!"

            ) ELSE (

                Rem | Find Largest
                for %%A in (!SUM1!, !String!) do (
                    set n=%%A
                    if !n! GTR !MAX! set MAX=!n!
                )

                Rem | Find Smallest
                for %%A in (!SUM1!, !String!) do (
                    set n=%%A
                    if !n! LSS !MAX! set MIN=!n!
                )
                Rem | Subtract 1st string from new
                Set /a "SUM2=!MAX!-!MIN!"

            )

            Rem | Add Each Differences
            Set /a "TOTAL=TOTAL+!SUM2!"

            Rem | Save Last Response
            Set "SUM1=!String!"

        ) ELSE (

            Rem | First Cycle, Set First String
            Set "SUM1=!String!"

            Rem | Disable This Check
            Set "WHOLE=2"

        )
    )
)
Rem | Do Math
Set /a "TRESULTS=!PingAmount!-1"
set /a "MEAN=!TOTAL!/!TRESULTS!"

Rem | Display Jitter
Echo The Jitter For The Above Arry Is: Jitter=!MEAN!ms
Echo(
goto LOOP

For help on any of the commands do the following:

  • call /?
  • set /?
  • for /?
  • if /?
  • find /?
  • So on.
John Kens
  • 1,615
  • 2
  • 10
  • 28