diff --git a/Ping_Monitor.ps1 b/Ping_Monitor.ps1 index 337346e..f00264a 100644 --- a/Ping_Monitor.ps1 +++ b/Ping_Monitor.ps1 @@ -1,16 +1,22 @@ # Define the IP addresses to monitor -$addresses = @( +$addresses = @() +$addressDefinitions = @( "1.1.1.1", "1.0.0.1", "8.8.8.8-9" # Using range notation for cleaner definition -) | ForEach-Object { - if ($_ -match "(\d+\.\d+\.\d+\.)(\d+)-(\d+)") { + +) + +foreach ($addr in $addressDefinitions) { + if ($addr -match "(\d+\.\d+\.\d+\.)(\d+)-(\d+)") { $prefix = $matches[1] $start = [int]$matches[2] $end = [int]$matches[3] - $start..$end | ForEach-Object { "$prefix$_" } + for ($i = $start; $i -le $end; $i++) { + $addresses += "$prefix$i" + } } else { - $_ + $addresses += $addr } } @@ -93,11 +99,11 @@ try { $stats[$addr].TotalTime += $responseTime $stats[$addr].SuccessCount++ - # Update rolling queue of samples + # Update rolling queue of samples - suppress output if ($stats[$addr].Samples.Count -eq 60) { - $stats[$addr].Samples.Dequeue() + [void]$stats[$addr].Samples.Dequeue() } - $stats[$addr].Samples.Enqueue($responseTime) + [void]$stats[$addr].Samples.Enqueue($responseTime) # Update min/max $stats[$addr].MinTime = [Math]::Min($stats[$addr].MinTime, $responseTime) @@ -126,7 +132,7 @@ try { [math]::Round((Get-Mean $stats[$addr].Samples), 1) } else { 0 } - # Calculate trend based on last 5 samples + # Calculate trend based on last 5 samples - suppress output $trend = if ($stats[$addr].Samples.Count -ge 5) { $recent = @([array]($stats[$addr].Samples)) $lastFive = $recent[-[Math]::Min(5, $recent.Count)..-1]