2021-09-27 10:38:12 +02:00
|
|
|
|
<#
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.SYNOPSIS
|
2022-10-28 12:39:58 +02:00
|
|
|
|
Checks the ping latency
|
2021-10-04 21:29:23 +02:00
|
|
|
|
.DESCRIPTION
|
2023-01-03 10:49:38 +01:00
|
|
|
|
This PowerShell script checks the ping latency from the local computer to the given hosts.
|
2021-10-16 16:50:10 +02:00
|
|
|
|
.PARAMETER hosts
|
2023-01-03 10:49:38 +01:00
|
|
|
|
Specifies the hosts to check, seperated by commata (default is: amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com)
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.EXAMPLE
|
2021-09-24 17:19:49 +02:00
|
|
|
|
PS> ./check-ping
|
2023-01-03 10:49:38 +01:00
|
|
|
|
✅ Ping latency is 13ms...109ms, 25ms average.
|
2021-07-13 21:10:02 +02:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
2022-09-06 21:42:04 +02:00
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
2021-03-30 09:06:30 +02:00
|
|
|
|
#>
|
|
|
|
|
|
2021-12-02 07:31:40 +01:00
|
|
|
|
param([string]$hosts = "amazon.com,bing.com,cnn.com,dropbox.com,facebook.com,google.com,live.com,twitter.com,youtube.com")
|
2021-09-21 20:19:39 +02:00
|
|
|
|
|
2021-03-30 09:06:30 +02:00
|
|
|
|
try {
|
2023-01-01 19:22:35 +01:00
|
|
|
|
Write-Progress "⏳ Pinging $hosts..."
|
2021-09-21 20:19:39 +02:00
|
|
|
|
$HostsArray = $hosts.Split(",")
|
2023-01-03 10:49:38 +01:00
|
|
|
|
$Pings = Test-Connection -computerName $HostsArray -count 1
|
2021-03-30 09:06:30 +02:00
|
|
|
|
|
2023-01-01 19:22:35 +01:00
|
|
|
|
Write-Progress "⏳ Calculating results..."
|
2021-03-30 09:06:30 +02:00
|
|
|
|
[int]$Min = 9999999
|
2022-10-28 12:39:58 +02:00
|
|
|
|
[int]$Max = [int]$Avg = 0
|
2021-03-30 09:06:30 +02:00
|
|
|
|
foreach($Ping in $Pings) {
|
2022-10-28 12:39:58 +02:00
|
|
|
|
if ($IsLinux) { [int]$Latency = $Ping.latency } else { [int]$Latency = $Ping.ResponseTime }
|
2021-03-30 09:43:58 +02:00
|
|
|
|
if ($Latency -lt $Min) { $Min = $Latency }
|
|
|
|
|
if ($Latency -gt $Max) { $Max = $Latency }
|
|
|
|
|
$Avg += $Latency
|
2021-03-30 09:06:30 +02:00
|
|
|
|
}
|
2022-10-11 19:51:04 +02:00
|
|
|
|
$Avg /= $Pings.count
|
2022-12-28 17:49:03 +01:00
|
|
|
|
|
2023-01-03 10:49:38 +01:00
|
|
|
|
Write-Host "✅ Ping latency is $($Min)ms...$($Max)ms, $($Avg)ms average"
|
2023-01-02 16:28:13 +01:00
|
|
|
|
Write-Progress -Completed " "
|
2021-09-27 10:09:45 +02:00
|
|
|
|
exit 0 # success
|
2021-03-30 09:06:30 +02:00
|
|
|
|
} catch {
|
2022-04-13 12:06:32 +02:00
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
2021-03-30 09:06:30 +02:00
|
|
|
|
exit 1
|
2022-10-28 12:39:58 +02:00
|
|
|
|
}
|