Update ping-remote-hosts.ps1

This commit is contained in:
Markus Fleschutz 2024-07-11 14:45:25 +02:00
parent c96f45fb42
commit 03175642e1

View File

@ -7,7 +7,7 @@
Specifies the hosts to ping, seperated by commata (10 Internet servers by default)
.EXAMPLE
PS> ./ping-remote-hosts.ps1
Online with 18ms latency (13...109ms, 0/10 ping loss)
Online with 0/10 ping loss and 11...40ms latency - 18ms average
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
@ -18,7 +18,7 @@ param([string]$hosts = "bing.com,cnn.com,dropbox.com,github.com,google.com,ibm.c
try {
$hostsArray = $hosts.Split(",")
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750) }
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,1000) }
[int]$min = 9999999
[int]$max = [int]$avg = [int]$success = 0
[int]$total = $hostsArray.Count
@ -34,7 +34,7 @@ try {
[int]$loss = $total - $success
if ($success -ne 0) {
$avg /= $success
Write-Host "✅ Online with $($avg)ms latency ($($min)...$($max)ms, $loss/$total ping loss)"
Write-Host "✅ Online with $loss/$total ping loss and $($min)...$($max)ms latency - $($avg)ms average"
} else {
Write-Host "⚠️ Offline ($loss/$total ping loss)"
}