mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-23 02:18:21 +02:00
Update check-ping.ps1
This commit is contained in:
parent
749eb47a2b
commit
977e037e72
@ -17,10 +17,9 @@
|
|||||||
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,github.com,google.com,live.com,twitter.com,youtube.com")
|
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,github.com,google.com,live.com,twitter.com,youtube.com")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Write-Host "✅ Ping latency is" -noNewline
|
|
||||||
$hostsArray = $hosts.Split(",")
|
$hostsArray = $hosts.Split(",")
|
||||||
$t = $hostsArray | foreach {
|
$t = $hostsArray | foreach {
|
||||||
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 250)
|
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 500)
|
||||||
}
|
}
|
||||||
[Threading.Tasks.Task]::WaitAll($t)
|
[Threading.Tasks.Task]::WaitAll($t)
|
||||||
[int]$min = 9999999
|
[int]$min = 9999999
|
||||||
@ -36,8 +35,12 @@ try {
|
|||||||
$lossCount++
|
$lossCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if ($successCount -eq 0) {
|
||||||
|
Write-Host "⚠️ Offline ($lossCount/$lossCount loss)"
|
||||||
|
} else {
|
||||||
$avg /= $successCount
|
$avg /= $successCount
|
||||||
Write-Host " $($avg)ms average ($($min)ms...$($max)ms, $lossCount loss)"
|
Write-Host "✅ Ping latency is $($avg)ms average ($($min)ms...$($max)ms, $lossCount loss)"
|
||||||
|
}
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
Loading…
Reference in New Issue
Block a user