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?
-
13Why on earth would you want to do this? There is no benefit of doing this, which is why ping itself can't do this.– LPChipCommented Sep 17, 2020 at 7:32
-
27@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.– jcaronCommented Sep 17, 2020 at 15:48
-
27@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).– jcaronCommented Sep 17, 2020 at 16:01
-
17@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.– fraxinusCommented Sep 17, 2020 at 19:56
-
19@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.– jcaronCommented Sep 17, 2020 at 23:50
7 Answers
You can take the System.Net.NetworkInformation.Ping class and wrap it in a PowerShell 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...}
-
Thanks for your support. Is it possible to use ip address instead of CompturName ?– geek225Commented Sep 17, 2020 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– SimonSCommented Sep 17, 2020 at 8:29 -
2I 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.– trlklyCommented Sep 19, 2020 at 10:19
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
-
8
-
3
-
3
You 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 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.
-
holly smokes that is amazing and terrifying. the power is right there.– TomachiCommented Sep 12, 2021 at 16:32
- 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.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
-
A super golfed version would be:
0..9|%{test-Connection 1.1.1.1 -cou 1;sleep -m 500}
– WasifCommented Sep 19, 2020 at 9:37 -
@WasifHasan I already added in the post, very good, thanks ...– Io-oICommented Sep 19, 2020 at 10:11
-
1i use
Test-Connection 1.0.0.1 -Cou 9999
for flood mode, there is no need to sleep/wait at all, although if you need can use param-Delay
instead ofseelp
command [while i use old version of powershell]. in new versions you can use-Repeat
and-TimeoutSeconds
params too > microsoft– a55Commented Jun 4 at 12:43 -
1@a55 Thanks for commenting, but please note that the question refers to 500 milliseconds and I can't use it because the syntax asks for integers:
[-Delay <int>]
and[-TimeoutSeconds <int>]
– Io-oICommented Jun 4 at 14:18
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
-
I looked into this. fPing is only a linux program, and TruePing gets deleted by my antivirus for being a trojan.– LPChipCommented Jul 4, 2022 at 9:33
A very simple way to do this is simply to run two pings each in their own window. (Not strictly 1 every 500ms, but it would be 2 per second.)
This gets cumbersome fast, but something like 5 at once is possible.
Thanks to @SimonS for accepted answer
I rewrite & improve it for personally usage
- flood mode
- wait for server response
- but dont wait betweens
- result just in one line
- different colors usage
- resize window too
Function New-IntervalPing {
[Alias("fping")]
Param(
[string]$Target,
[int]$TimeOut = 200
)
mode 20,64
while(1) {
$Ping = [System.Net.NetworkInformation.Ping]::New()
$Res = $Ping.Send($Target,$TimeOut,[byte[]]::new(1))
Write-Host -NoNewline $Target "> "
$color = if($Res.RoundtripTime -eq "0"){"red"}else{"green"}
Write-Host -ForegroundColor $color $Res.RoundtripTime
}
}
Usage
fping 1.0.0.1
if you dont like window size changes, can comment it like # mode 20,64