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)
|
Specifies the hosts to ping, seperated by commata (10 Internet servers by default)
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
PS> ./ping-remote-hosts.ps1
|
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
|
.LINK
|
||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
.NOTES
|
.NOTES
|
||||||
@ -18,14 +18,12 @@ param([string]$hosts = "bing.com,cnn.com,dropbox.com,github.com,google.com,ibm.c
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$hostsArray = $hosts.Split(",")
|
$hostsArray = $hosts.Split(",")
|
||||||
$parallelTasks = $hostsArray | foreach {
|
$tasks = $hostsArray | foreach { (New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750) }
|
||||||
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_,750)
|
|
||||||
}
|
|
||||||
[int]$min = 9999999
|
[int]$min = 9999999
|
||||||
[int]$max = [int]$avg = [int]$success = 0
|
[int]$max = [int]$avg = [int]$success = 0
|
||||||
[int]$total = $hostsArray.Count
|
[int]$total = $hostsArray.Count
|
||||||
[Threading.Tasks.Task]::WaitAll($parallelTasks)
|
[Threading.Tasks.Task]::WaitAll($tasks)
|
||||||
foreach($ping in $parallelTasks.Result) {
|
foreach($ping in $tasks.Result) {
|
||||||
if ($ping.Status -ne "Success") { continue }
|
if ($ping.Status -ne "Success") { continue }
|
||||||
$success++
|
$success++
|
||||||
[int]$latency = $ping.RoundtripTime
|
[int]$latency = $ping.RoundtripTime
|
||||||
@ -36,7 +34,7 @@ try {
|
|||||||
[int]$loss = $total - $success
|
[int]$loss = $total - $success
|
||||||
if ($success -ne 0) {
|
if ($success -ne 0) {
|
||||||
$avg /= $success
|
$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 {
|
} else {
|
||||||
Write-Host "⚠️ Offline ($loss/$total ping loss)"
|
Write-Host "⚠️ Offline ($loss/$total ping loss)"
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user