18

By default the time delay between two pings is equal to 1 second. My need is to reduce the delay between two pings to 500 ms (0.5 seconds). Is there any way to do this?

14
  • 13
    Why on earth would you want to do this? There is no benefit of doing this, which is why ping itself can't do this.
    – LPChip
    Sep 17 '20 at 7:32
  • 21
    @LPChip That's an interesting theory, but sending more than 1 ping per second is actually something very common. When you want to measure packet loss with reasonable precision and don't want to spend hours doing it, reducing the interval to a fraction of a second is the way to go.
    – jcaron
    Sep 17 '20 at 15:48
  • 22
    @LPChip To get a reasonable measure of packet loss, you need to send many packets. Like 100. If you are stuck with a 1 second interval, it takes 100 seconds. If you can send them a 0.1 or 0.01 intervals, it takes 10 seconds or 1 second. Also, increasing packet size does not help you measuring packet loss for a given size (packet loss may vary with the size of the packets).
    – jcaron
    Sep 17 '20 at 16:01
  • 16
    @LPChip Longer and shorter packets have somewhat different failure modes so it sometimes makes sense to use different length. Then again, using longer ot shorter pauses is pretty much legitimate and that's why ping has corresponding options. On Windows, the pause is hardcoded to 1s, but on Linux the pause is limited only by the network stack performance.
    – fraxinus
    Sep 17 '20 at 19:56
  • 17
    @LPChip Interesting analogy, but actually wrong. Increasing packet size increases your chances of dropping packets if the reason for the packet loss is errors on the link. Increasing frequency does not. Changing one or the other means you don't measure the same thing. At all.
    – jcaron
    Sep 17 '20 at 23:50
17

You could create an endless loop in PowerShell, send 1 ping there and wait for 500ms after sending it.

while ($true) { Test-Connection ServerName -Count 1 ; Start-Sleep -MilliSeconds 500 }

You can also Wrap it in a Function and put in in your PowerShell Profile to use it anytime

Function New-Ping {
    
    Param(
        [Parameter(Mandatory)]
        [string]$ComputerName,
        [Parameter(Mandatory)]
        [int]$Intervall
    )

    while ($true) { 
        Test-Connection $ComputerName -Count 1
        Start-Sleep -MilliSeconds $Intervall 
    }
}

and use it like this from within PowerShell:

New-Ping ServerName 500

You can also use it in cmd.exe like so:

C:\WINDOWS\system32>powershell new-ping SRV 500

Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms)
------        -----------     -----------      -----------                              -----    --------
CP            SRV            10.0.0.226                                                32       0
CP            SRV            10.0.0.226                                                32       0
CP            SRV            10.0.0.226                                                32       0

You can end the endless loop by pressing CTRL + C

3
  • Thanks for your support. Is it possible to use ip address instead of CompturName ?
    – geek225
    Sep 17 '20 at 8:26
  • 1
    @geek225 yes, you can also specify an IP Adress instead: New-Ping 10.0.0.226 500. Test-Connection doesn't care if it's IP or Name
    – SimonS
    Sep 17 '20 at 8:29
  • 2
    I like this one because it doesn't required installing a separate app. I always think the best Answer should at least provide a way to do that, even if using a separate program is easier.
    – trlkly
    Sep 19 '20 at 10:19
18

You can do this with nping (from the makers of nmap)

  1. First download and install the nmap package which includes nping.
  2. In a command prompt change the directory to C:\Program Files (x86)\Nmap
  3. Now run the following command: nping --delay 500ms --count 0 <target ip address>
    (the --count 0 option sets it to a continuous ping)

....from Nping Reference Guide:

Usage: nping [Probe mode] [Options] {target specification}
....
....
TIMING AND PERFORMANCE:
  Options which take <time> are in seconds, or append 'ms' (milliseconds),
  's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m, 0.25h).
  --delay <time>                   : Adjust delay between probes.
  --rate  <rate>                   : Send num packets per second.
1
  • holly smokes that is amazing and terrifying. the power is right there.
    – Tomachi
    Sep 12 at 16:32
16

On Linux it is possible (recently minimum time was changed to 200ms = 0.2):

ping -i 0.2 server.com

Root can issue shorter time:

ping -i 0.01 server.com
4
  • 7
    one would need to use 0.5 to achieve 500ms
    – JCRM
    Sep 18 '20 at 12:59
  • 3
    And the tags mention windows (cmd.exe) Sep 20 '20 at 6:18
  • This also works on macOS.
    – Seafish
    Feb 28 at 16:10
  • my fans went crazy. lordy.
    – Tomachi
    Sep 12 at 16:33
9

You can't change the time between each ping request in the Windows command line. You'll need a 3rd party tool like fping or TruePing

Also see https://serverfault.com/questions/200468/how-can-i-set-a-short-timeout-with-the-ping-command

8
  • In PowerShell
$cnt=0; while ($cnt -le 9) {$cnt++; Start-Sleep -MilliSeconds 500; Test-Connection 1.1.1.1 -Count 1}
  • One option using aliases:
$cnt=0;while($cnt -le 9){$cnt++;Test-Connection 1.1.1.1  -Cou 1; sleep -M 500} 

Super golfed version from @wasif-hasan comment suggestion:

0..9|%{test-Connection 1.1.1.1 -cou 1;sleep -m 500}
  • Outputs/Results:
Source        Destination     IPV4Address      IPV6Address                              Bytes    Time(ms) 
------        -----------     -----------      -----------                              -----    -------- 
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       18       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       20       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       15       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       17       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       15       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       19       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       16       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       16       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       18       
LAME_SLUG     1.1.1.1         1.1.1.1          2606:4700:4700::1111                     32       19 



  • In Bat/CMD:
@echo off 

:loop
pathping 127.1 -n -q 1 -p 500 >nul 2>nul 
ping 151.101.193.69 -n 1 -4 & goto=:loop
  • Or with a predefined ping/loop limit:

@echo off & setlocal

:loop pathping 127.1 -n -q 1 -p 500 >nul 2>nul ping 1.1.1.1 -n 1 -4 & set /a "_cnt+=1+0" if %_cnt% leq 10 (goto:loop)else goto:eof


Use pathping from Microsoft and comes with Windows

C:\Users\ecker>where pathping
C:\Windows\System32\PATHPING.EXE

C:\Users\ecker>PATHPING.EXE /?
Usage: pathping [-g host-list] [-h maximum_hops] [-i address] [-n]
                [-p period] [-q num_queries] [-w timeout]
                [-4] [-6] target_name

Options:
    -g host-list     Loose source route along host-list.
    -h maximum_hops  Maximum number of hops to search for target.
    -i address       Use the specified source address.
    -n               Do not resolve addresses to hostnames.
    -p period        Wait period milliseconds between pings.
    -q num_queries   Number of queries per hop.
    -w timeout       Wait timeout milliseconds for each reply.
    -4               Force using IPv4.
    -6               Force using IPv6.

Obs.: When -p is specified, pings are sent individually to each intermediate hop. When -w is specified, multiple pings can be sent in parallel. It is therefore possible to choose a Timeout parameter that is less than the wait Period * Number of hops.


  • Some further reading for cmd/bat:

    [√] PathPing

2
  • A super golfed version would be: 0..9|%{test-Connection 1.1.1.1 -cou 1;sleep -m 500} Sep 19 '20 at 9:37
  • @WasifHasan I already added in the post, very good, thanks ... Sep 19 '20 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.