Update check-ping.ps1

This commit is contained in:
Markus Fleschutz 2023-06-02 13:09:21 +02:00
parent fa3865a9a9
commit f60c8e0577

View File

@ -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) 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 .EXAMPLE
PS> ./check-ping PS> ./check-ping
Ping latency is 13ms...109ms with 25ms average Ping latency is 13ms...109ms with 29ms average (0 loss)
.LINK .LINK
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
.NOTES .NOTES
@ -25,18 +25,20 @@ try {
} }
[Threading.Tasks.Task]::WaitAll($t) [Threading.Tasks.Task]::WaitAll($t)
[int]$Min = 9999999 [int]$Min = 9999999
[int]$Max = [int]$Avg = [int]$Count = 0 [int]$Max = [int]$Avg = [int]$SuccessCount = [int]$LossCount = 0
foreach($ping in $t.Result) { foreach($ping in $t.Result) {
if ($ping.Status -eq "Success") { if ($ping.Status -eq "Success") {
[int]$Latency = $ping.RoundtripTime [int]$Latency = $ping.RoundtripTime
if ($Latency -lt $Min) { $Min = $Latency } if ($Latency -lt $Min) { $Min = $Latency }
if ($Latency -gt $Max) { $Max = $Latency } if ($Latency -gt $Max) { $Max = $Latency }
$Avg += $Latency $Avg += $Latency
$Count++ $SuccessCount++
} else {
$LossCount++
} }
} }
$Avg /= $Count $Avg /= $SuccessCount
Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average" Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average ($LossCount loss)"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"