windows - How to record ping statistics in tabular format? -


i need record ping statistics tabular format on windows.

c:\users\hsangal>ping localhost -t -n 2  pinging techbeamers.local [127.0.0.1] 32 bytes of data: reply 127.0.0.1: bytes=32 time<1ms ttl=128 reply 127.0.0.1: bytes=32 time<1ms ttl=128  ping statistics 127.0.0.1: packets: sent = 2, received = 2, lost = 0 (0% loss) approximate round trip times in milli-seconds:     minimum = 0ms, maximum = 0ms, average = 0ms 

i using windows batch scripting, looking lead experts. data wish record in tabular format part of ping command output highlighted below:

packets: sent = 2, received = 2, lost = 0 (0% loss) 

you use find lines information of interest only, like:

ping localhost -n 2 | find "packets:" 

this returns line packets: sent = 2, received = 2, lost = 0 (0% loss),.
wrap around for /f statement this:

for /f "tokens=3,5,7,8 delims=,=() " %i in ('ping localhost -n 2 ^| find "packets:"') echo %i;%j;%k;%l 

the output (sent packets;received packets;lost packets;% loss):

2;2;0;0% 

of course may specify (a) delimiter(s) other ; (just exchange in final echo statement).
regard above code works if directly entered command prompt. if want use within batch file, replace variables %i etc. %%i.

note: -t switch in ping command line ignored when provide -n switch.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -