mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-22 21:58:42 +01:00
Update check-ping.ps1
This commit is contained in:
parent
9ef8b1f891
commit
140f47049b
@ -17,19 +17,38 @@
|
||||
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(",")
|
||||
$Pings = Test-Connection -computerName $HostsArray -count 1
|
||||
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
|
||||
[int]$Max = [int]$Avg = 0
|
||||
foreach($Ping in $Pings) {
|
||||
if ($IsLinux) { [int]$Latency = $Ping.latency } else { [int]$Latency = $Ping.ResponseTime }
|
||||
if ($Latency -lt $Min) { $Min = $Latency }
|
||||
if ($Latency -gt $Max) { $Max = $Latency }
|
||||
$Avg += $Latency
|
||||
[int]$Min = 9999999
|
||||
[int]$Max = [int]$Avg = 0
|
||||
foreach($Ping in $Pings) {
|
||||
if ($IsLinux) { [int]$Latency = $Ping.latency } else { [int]$Latency = $Ping.ResponseTime }
|
||||
if ($Latency -lt $Min) { $Min = $Latency }
|
||||
if ($Latency -gt $Max) { $Max = $Latency }
|
||||
$Avg += $Latency
|
||||
}
|
||||
$Avg /= $Pings.count
|
||||
}
|
||||
$Avg /= $Pings.count
|
||||
|
||||
Write-Progress -Completed "."
|
||||
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms with $($Avg)ms average"
|
||||
@ -37,4 +56,4 @@ try {
|
||||
} catch {
|
||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user