Update check-ping.ps1

This commit is contained in:
Markus Fleschutz 2023-06-02 12:29:49 +02:00
parent 9ef8b1f891
commit 140f47049b

View File

@ -17,8 +17,26 @@
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
try {
Write-Progress "⏳ Sending a ping to 9 popular hosts..."
Write-Progress "⏳ Sending pings to 9 popular hosts..."
$HostsArray = $hosts.Split(",")
if ($IsLinux) {
$t = $HostsArray | foreach {
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 250)
}
[Threading.Tasks.Task]::WaitAll($t)
[int]$Min = 9999999
[int]$Max = [int]$Avg = [int]$Count = 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++
}
}
$Avg /= $Count
} else {
$Pings = Test-Connection -computerName $HostsArray -count 1
[int]$Min = 9999999
@ -30,6 +48,7 @@ try {
$Avg += $Latency
}
$Avg /= $Pings.count
}
Write-Progress -Completed "."
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms with $($Avg)ms average"