Skip to content

Instantly share code, notes, and snippets.

@gwarser
Created November 24, 2012 07:51
Show Gist options
  • Save gwarser/4138817 to your computer and use it in GitHub Desktop.
Save gwarser/4138817 to your computer and use it in GitHub Desktop.
ping histogram in cmd (batch)
@echo off
rem -*- coding: cp852 -*-
rem ▀▄█░▒▓■
setlocal enabledelayedexpansion
set host=google.com
set timeout=1000
set avgc=12
set /a linediv=!timeout! / 79
set sum=
:loop
set skip=1
for /f "delims=m= tokens=3" %%I in ('ping -n 1 -w 1000 %host% ^| find "TTL="') do (
set skip=0
set /a cnt=^(%%I + !linediv!^) / !linediv!
set p=░
set l=
for /l %%K in (0, 1, !cnt!) do (
if %%K gtr 79 (set p=+)
set l=!l!!p!
)
echo !l!
call :push %%I !avgc!
call :sum !avgc!
set /a avg=!sum! / !avgc!
set /a cnt=^(!avg! + !linediv!^) / !linediv!
set p=█
set l=
for /l %%K in (0, 1, !cnt!) do (
if %%K gtr 79 (set p=-)
set l=!l!!p!
)
echo !l!
title %%Ims avg^(!avgc!^):!avg!ms
)
if %skip%==1 echo ~
ping 127.0.0.1 -n 2 >nul
goto loop
goto :eof
:push
for /l %%I in (1, 1, %2) do (
set /a j=%%I - 1
if "!stack%%I!"=="" set stack%%I=%1
set tmp!j!=!stack%%I!
)
set tmp%2=%1
for /l %%I in (1, 1, %2) do (
set stack%%I=!tmp%%I!
)
goto :eof
:sum
set sum=0
for /l %%I in (1, 1, %1) do (
set /a sum=!sum! + !stack%%I!
)
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment