diff --git a/Scripts/check-ping.ps1 b/Scripts/check-ping.ps1 index eca1b14e..ae677665 100755 --- a/Scripts/check-ping.ps1 +++ b/Scripts/check-ping.ps1 @@ -7,7 +7,7 @@ Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,github.com,google.com,live.com,twitter.com,youtube.com) .EXAMPLE PS> ./check-ping - ✅ Ping latency is 13ms...109ms with 25ms average + ✅ Ping latency is 13ms...109ms with 29ms average (0 loss) .LINK https://github.com/fleschutz/PowerShell .NOTES @@ -25,18 +25,20 @@ try { } [Threading.Tasks.Task]::WaitAll($t) [int]$Min = 9999999 - [int]$Max = [int]$Avg = [int]$Count = 0 + [int]$Max = [int]$Avg = [int]$SuccessCount = [int]$LossCount = 0 foreach($ping in $t.Result) { if ($ping.Status -eq "Success") { [int]$Latency = $ping.RoundtripTime if ($Latency -lt $Min) { $Min = $Latency } if ($Latency -gt $Max) { $Max = $Latency } $Avg += $Latency - $Count++ + $SuccessCount++ + } else { + $LossCount++ } } - $Avg /= $Count - Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average" + $Avg /= $SuccessCount + Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average ($LossCount loss)" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"