This is a fairly well known issue with PING on a windows System.
When running PING with only 1 iteration it can behave unexpectedly, and even ping at LESS than 1 second on the 1st timeout, when the timeout is set to 1 second, which is more strange than the delay added, but not that uncommon (see below I captured one such example it he wild.).
The default timeout is also not stated clearly, but is 3 seconds.
You can test ping and see it behaving wildly with 1 ping set at any value less than 2 seconds, but really the matter seems to be that it can fluxuate by about 500 MS above the value expected due to overhead in instantiating the ping command and calling the TCP/IP stack etc.
I have worked with systems I set up with 10g NICs on a port agg to a nexus switch offloading most of the TCP/IP work to the physical card where the value specified to ping didn't have almost any issue with the timeout.
However I have found that wrapping the PING
command inside of a For /F loop will actually reduce the time needed to execute the pings noticeably making it more likely to be.
The only Other alternative is to spawn many parallel command windows, echo the results to a file and then read it, which is still faster.
You can test on the CLI by running this:
echo=%time%&ping -n 1 10.180.7.10>NUL&CALL echo=^%time^%
Note that Ping behaves much more consistently at -n 2
and greater, or with 2000 MS timout or greater.
There the default will be 1 second between timeouts with a fluxulation of x milliseconds, usually the fluxation is much smaller about 100 - 200 ms.
here are some examples from a VM I have:
Cherry Picked:
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 10 10.180.7.10 >NUL&echo=!time!
0:19:35.16
0:19:35.45
(300 MS per ping)
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1000 10.180.7.10 >NUL&echo=!time!
0:21:49.29
0:21:49.95
(660 MS per ping)
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1000 10.180.7.10 >NUL&echo=!time!
0:22:41.45
0:22:42.45
(1000 MS per Ping)
C:\Windows\system32>ECHO=!TIME!&Ping -n 2 -l 1 -4 -w 1 10.180.7.10 >NUL&echo=!time!
0:19:57.54
0:19:59.45
(1910 MS - AKA: 955 MS per Ping)
C:\Windows\system32>ECHO=!TIME!&Ping -n 10 -l 1 -4 -w 10 10.180.7.10 >NUL&echo=!time!
0:18:33.11
0:18:46.96
(13850 MS - AKA: 1385 MS per Ping)
C:\Windows\system32>ECHO=!TIME!&Ping -n 10 -l 1 -4 -w 1 10.180.7.1 >NUL&echo=!time!
0:20:33.93
0:20:42.99
(9060 MS - AKA: 906 MS per ping)
Larger Set:
C:\Windows\system32>cmd /v
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Windows\system32>ECHO=!TIME!&Ping -n 10 -l 1 -4 -w 10 10.180.7.10 >NUL&echo=!time!
0:18:33.11
0:18:46.96
C:\Windows\system32>ECHO=!TIME!&Ping -n 10 -l 1 -4 -w 10 10.180.7.10 >NUL&echo=!time!
0:19:12.39
0:19:25.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 10 10.180.7.10 >NUL&echo=!time!
0:19:35.16
0:19:35.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1 10.180.7.10 >NUL&echo=!time!
0:19:43.61
0:19:43.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 2 -l 1 -4 -w 1 10.180.7.10 >NUL&echo=!time!
0:19:57.54
0:19:59.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 2 -l 1 -4 -w 1 10.180.7.1 >NUL&echo=!time!
0:20:14.24
0:20:15.29
C:\Windows\system32>ECHO=!TIME!&Ping -n 10 -l 1 -4 -w 1 10.180.7.1 >NUL&echo=!time!
0:20:33.93
0:20:42.99
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1 10.180.7.1 >NUL&echo=!time!
0:20:57.54
0:20:57.60
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1 10.180.7.10 >NUL&echo=!time!
0:21:08.76
0:21:08.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:21:43.01
0:21:43.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1000 10.180.7.10 >NUL&echo=!time!
0:21:49.29
0:21:49.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 2000 10.180.7.10 >NUL&echo=!time!
0:22:22.54
0:22:24.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 2000 10.180.7.10 >NUL&echo=!time!
0:22:34.04
0:22:35.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 1000 10.180.7.10 >NUL&echo=!time!
0:22:41.45
0:22:42.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 500 10.180.7.10 >NUL&echo=!time!
0:22:53.92
0:22:54.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:23:01.53
0:23:01.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:23:05.81
0:23:05.95
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:23:08.98
0:23:09.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:23:12.93
0:23:13.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 100 10.180.7.10 >NUL&echo=!time!
0:23:19.37
0:23:19.45
C:\Windows\system32>ECHO=!TIME!&Ping -n 1 -l 1 -4 -w 2300 10.180.7.10 >NUL&echo=!time!
0:43:17.04
0:43:18.95
A Faster alternatives
One faster alternative is to Wrap Ping
in a For /F
loop
@ECHO OFF
FOR /f "tokens=2 delims=:" %%a in ('
ipconfig^|find "IPv4"
') do (
FOR /f "tokens=1-3 delims=. " %%A in ("%%a") do (
ECHO="%%a"_"%%b" ECHO="%%A"_"%%B"_"%%C"
FOR /l %%L in (0,1,255) DO (
FOR /F "Tokens=*" %%l IN ('
ping -n 1 -w 100 %%A.%%B.%%C.%%L
^| FIND /I /V "Pinging "
^| FIND /I /V "Ping Statistics FOR"
^| FIND /I /V "Packets: "
^| FIND /I /V "Approximate round trip "
^| FIND /I /V "Minimum = "
') DO (
CALL ECHO. ^%%TIME^%% - %%A.%%B.%%C.%%L -- %%l
)
)
)
)
Another Faster Alternative method to ping a large set of addresses is to parallelize the pinging and output to a file, and then type the contents
@ECHO OFF
FOR /f "tokens=2 delims=:" %%a in ('
ipconfig^|find "IPv4"
') do (
FOR /f "tokens=1-3 delims=. " %%A in ("%%a") do (
ECHO="%%a"_"%%b" ECHO="%%A"_"%%B"_"%%C"
FOR /l %%L in (0,1,255) DO (
START CMD /C "ping -n 1 -w 100 %%A.%%B.%%C.%%L >>%%A.%%B.%%C.%%L_Ping.log"
)
)
)
timeout 10
for /R %%_ IN (*_Ping.log) DO (
FOR /F "Tokens=*" %%l IN ('
TYPE "%%~f_" | FIND /I /V "Pinging " | FIND /I /V "Ping Statistics FOR" | FIND /I /V "Packets: " | FIND /I /V "Approximate round trip " | FIND /I /V "Minimum = "
') DO (
FOR /F "Tokens=1 delims=_" %%# IN ("%%~n_") DO (
CALL ECHO. %%TIME%% - %%# -- %%l
)
)
)