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?
145 Answers
Edit 17.05.2022
An even better alternative would be to use the System.Net.NetworkInformation.Ping class and wrap it in a function. I kept it very easy, you can tinker with it to get the output you want.
Here's the function:
- Computername accepts internal + external IP Adresses, ComputerNames, URLs etc.
- Count = How many ping packets to send
- Timeout specifies the maximum number of milliseconds (after sending the echo message) to wait for the ICMP echo reply message.
- Interval = How many milliseconds to wait before next ping.
.
Function New-IntervalPing { [Alias("iping")] Param( [string]$ComputerName, [int]$Count = 4, [int]$TimeOut = 100, [int]$Interval = 500 ) 1..$Count | ForEach-Object { $Ping = [System.Net.NetworkInformation.Ping]::New() $Ping.Send($ComputerName,$TimeOut) start-sleep -Milliseconds $Interval } } usage:
PS C:\Users\SimonS> iping google.com -count 2 -interval 300 Status : Success Address : 172.217.168.14 RoundtripTime : 6 Options : System.Net.NetworkInformation.PingOptions Buffer : {97, 98, 99, 100...} Status : Success Address : 172.217.168.14 RoundtripTime : 4 Options : System.Net.NetworkInformation.PingOptions Buffer : {97, 98, 99, 100...} Answer before 17.05.2022
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
3You can do this with nping (from the makers of nmap)
- First download and install the nmap package which includes nping.
- In a command prompt change the directory to
C:\Program Files (x86)\Nmap - Now run the following command:
nping --delay 500ms --count 0 <target ip address>
(the--count 0option 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. 1On 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 4You 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
- 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 Some further reading for PowerShell:
[√] While | $cnt+
[√] Test-Connection
- 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.EXEC:\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