-1

How to get the time and response round-trip delay (RTD) of a ping command?

ping 10.11.12.13 -n 1 

every second in the following format:

 [time] [delay]
 [time] [delay]
 [time] [delay]
 ...

...in a rich Windows command-line application with a Unix command set like Cmder or ConEmu, Cygwin...

Example of output:

12:00:01.123  20 ms
12:00:02.432  21 ms
...  
Supersharp
  • 29,002
  • 9
  • 92
  • 134

2 Answers2

0

A possible solution is to use the sed command. That will still work in case of tiemout.

@echo off
:debut

FOR /F "tokens=*" %%i IN ('ping 10.11.12.13 -n 1 ^| sed -n "3p" ^| sed -r "s/.*time.(.*)\sTTL.*/\1/"' ) DO echo %time%   %%i

sleep 1
goto debut

The first sed command extract the 3rd line which contains the delay in ms.

The second sed command extract the delay value, which is after "time" in and before " TTL".

NB: you can replace time by temps for an French version of ping on Windows.

Supersharp
  • 29,002
  • 9
  • 92
  • 134
  • 1
    Microsoft Windows does not include a `sed` command. The OP may or may not be permitted to install additional software on the machine. – lit Mar 12 '19 at 20:16
0

This is reasonably easily accomplished by letting PowerShell get the time and format the timestamp.

SET "RHOST=www.ibm.com"

powershell -NoLogo -NoProfile -Command ^
    "Test-Connection -ComputerName '%RHOST%' |" ^
        "ForEach-Object { '{0}  {1} ms' -f (Get-Date).ToString('HH:MM:ss.fff'), $_.ResponseTime }"

Of course, it is easier if the script is just written in PowerShell.

Test-Connection -ComputerName 'www.ibm.com' |
    ForEach-Object {
         '{0}  {1} ms' -f (Get-Date).ToString('HH:MM:ss.fff'), $_.ResponseTime
    }
lit
  • 14,456
  • 10
  • 65
  • 119