mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-08 00:54:04 +01:00
Update ping-remote-hosts.ps1
This commit is contained in:
parent
f74ab0c771
commit
902f19c64a
@ -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 (13ms...109ms, 0/10 ping loss)
|
||||
✅ Online with 18ms latency (13...109ms, 0/10 ping loss)
|
||||
.LINK
|
||||
https://github.com/fleschutz/PowerShell
|
||||
.NOTES
|
||||
@ -18,14 +18,12 @@ param([string]$hosts = "bing.com,cnn.com,dropbox.com,github.com,google.com,ibm.c
|
||||
|
||||
try {
|
||||
$hostsArray = $hosts.Split(",")
|
||||
$parallelTasks = $hostsArray | foreach {
|
||||
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750)
|
||||
}
|
||||
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750) }
|
||||
[int]$min = 9999999
|
||||
[int]$max = [int]$avg = [int]$success = 0
|
||||
[int]$total = $hostsArray.Count
|
||||
[Threading.Tasks.Task]::WaitAll($parallelTasks)
|
||||
foreach($ping in $parallelTasks.Result) {
|
||||
[Threading.Tasks.Task]::WaitAll($tasks)
|
||||
foreach($ping in $tasks.Result) {
|
||||
if ($ping.Status -ne "Success") { continue }
|
||||
$success++
|
||||
[int]$latency = $ping.RoundtripTime
|
||||
@ -36,7 +34,7 @@ try {
|
||||
[int]$loss = $total - $success
|
||||
if ($success -ne 0) {
|
||||
$avg /= $success
|
||||
Write-Host "✅ Online with $($avg)ms latency ($($min)ms...$($max)ms, $loss/$total ping loss)"
|
||||
Write-Host "✅ Online with $($avg)ms latency ($($min)...$($max)ms, $loss/$total ping loss)"
|
||||
} else {
|
||||
Write-Host "⚠️ Offline ($loss/$total ping loss)"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user