Skip to content

Commit 5e38219

Browse files
committed
Update check-ping.ps1
1 parent f8e9567 commit 5e38219

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Scripts/check-ping.ps1

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
.SYNOPSIS
33
Checks the ping latency
44
.DESCRIPTION
5-
This PowerShell script checks the ping latency from the local computer to 10 popular hosts.
5+
This PowerShell script measures the ping roundtrip times from the local computer to 10 Internet servers.
66
.PARAMETER hosts
77
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,github.com,google.com,live.com,twitter.com,youtube.com)
88
.EXAMPLE
99
PS> ./check-ping
10-
✅ Ping latency is 13ms...109ms with 29ms average (0 loss)
10+
✅ Ping latency is 29ms average (13ms...109ms, 0 loss)
1111
.LINK
1212
https://github.com/fleschutz/PowerShell
1313
.NOTES
@@ -18,27 +18,26 @@ param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,git
1818

1919
try {
2020
Write-Host "✅ Ping latency is" -noNewline
21-
$HostsArray = $hosts.Split(",")
22-
23-
$t = $HostsArray | foreach {
21+
$hostsArray = $hosts.Split(",")
22+
$t = $hostsArray | foreach {
2423
(New-Object Net.NetworkInformation.Ping).SendPingAsync($_, 250)
2524
}
2625
[Threading.Tasks.Task]::WaitAll($t)
27-
[int]$Min = 9999999
28-
[int]$Max = [int]$Avg = [int]$SuccessCount = [int]$LossCount = 0
26+
[int]$min = 9999999
27+
[int]$max = [int]$avg = [int]$successCount = [int]$lossCount = 0
2928
foreach($ping in $t.Result) {
3029
if ($ping.Status -eq "Success") {
31-
[int]$Latency = $ping.RoundtripTime
32-
if ($Latency -lt $Min) { $Min = $Latency }
33-
if ($Latency -gt $Max) { $Max = $Latency }
34-
$Avg += $Latency
35-
$SuccessCount++
30+
[int]$latency = $ping.RoundtripTime
31+
if ($latency -lt $min) { $min = $Latency }
32+
if ($latency -gt $max) { $max = $Latency }
33+
$avg += $latency
34+
$successCount++
3635
} else {
37-
$LossCount++
36+
$lossCount++
3837
}
3938
}
40-
$Avg /= $SuccessCount
41-
Write-Host " $($Min)ms...$($Max)ms with $($Avg)ms average ($LossCount loss)"
39+
$avg /= $successCount
40+
Write-Host " $($avg)ms average ($($min)ms...$($max)ms, $lossCount loss)"
4241
exit 0 # success
4342
} catch {
4443
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"

0 commit comments

Comments
 (0)