mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-01-23 06:08:36 +01:00
Update check-ping.ps1
This commit is contained in:
parent
9ef8b1f891
commit
140f47049b
@ -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")
|
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Progress "⏳ Sending a ping to 9 popular hosts..."
|
Write-Progress "⏳ Sending pings to 9 popular hosts..."
|
||||||
$HostsArray = $hosts.Split(",")
|
$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
|
$Pings = Test-Connection -computerName $HostsArray -count 1
|
||||||
|
|
||||||
[int]$Min = 9999999
|
[int]$Min = 9999999
|
||||||
@ -30,6 +48,7 @@ try {
|
|||||||
$Avg += $Latency
|
$Avg += $Latency
|
||||||
}
|
}
|
||||||
$Avg /= $Pings.count
|
$Avg /= $Pings.count
|
||||||
|
}
|
||||||
|
|
||||||
Write-Progress -Completed "."
|
Write-Progress -Completed "."
|
||||||
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms with $($Avg)ms average"
|
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms with $($Avg)ms average"
|
||||||
|
Loading…
Reference in New Issue
Block a user