Загрузка данных


$stats = @{}
$targets = @(
    '8.8.8.8', '1.1.1.1', '77.88.8.8', 'yandex.ru', 'vk.com', 
    'mail.ru', 'telegram.org', 'rutube.ru', 'dzen.ru', 'ok.ru', 
    'ozon.ru', 'wildberries.ru', 'avito.ru', 'lamoda.ru', 'dns-shop.ru', 
    'citilink.ru', 'mvideo.ru', 'sberbank.ru', 'tbank.ru', 'vtb.ru', 
    'alfabank.ru', 'gosuslugi.ru', 'nalog.gov.ru', 'mos.ru', '2gis.ru', 
    'kinopoisk.ru', 'kassir.ru', 'rbc.ru', 'ria.ru', 'lenta.ru', 
    'habr.com', 'github.com', 'mts.ru', 'megafon.ru', 'beeline.ru', 
    'tele2.ru', 'rostelecom.ru', 'store.steampowered.com', 'epicgames.com', 'lesta.ru'
)

foreach ($t in $targets) {
    $stats[$t] = [PSCustomObject]@{ Sent = 0; Lost = 0; Times = [System.Collections.Generic.List[int]]::new() }
}

while ($true) {
    $now = Get-Date -Format 'HH:mm:ss'
    Write-Host "`n=== ТЕКУЩИЙ ОПРОС [$now] ===" -ForegroundColor Cyan

    foreach ($target in $targets) {
        $item = $stats[$target]
        $pings = Test-Connection -ComputerName $target -Count 3 -ErrorAction SilentlyContinue
        $item.Sent += 3
        
        if ($pings) {
            $lostCount = 3 - $pings.Count
            $item.Lost += $lostCount
            
            foreach ($p in $pings) { $item.Times.Add($p.ResponseTime) }
            
            $curLoss = [math]::Round(($lostCount / 3) * 100)
            $avgPing = [math]::Round(($pings | Measure-Object -Property ResponseTime -Average).Average)
            $color = if ($curLoss -gt 0) { "Yellow" } else { "Green" }
            
            Write-Host "[$now] $target : Loss = $curLoss% | Avg = $avgPing ms" -ForegroundColor $color
        } else {
            $item.Lost += 3
            Write-Host "[$now] $target : 100% TIMEOUT" -ForegroundColor Red
        }
    }

    Write-Host "`n================ СВОДНАЯ СТАТИСТИКА ЗА ВСЕ ВРЕМЯ ================" -ForegroundColor Yellow
    foreach ($target in ($targets | Sort-Object)) {
        $item = $stats[$target]
        $total = $item.Sent
        $lost = $item.Lost
        $lossPerc = if ($total -gt 0) { [math]::Round(($lost / $total) * 100, 1) } else { 0 }
        
        if ($item.Times.Count -gt 0) {
            $min = ($item.Times | Measure-Object -Minimum).Minimum
            $max = ($item.Times | Measure-Object -Maximum).Maximum
            $avg = [math]::Round(($item.Times | Measure-Object -Average).Average)
        } else {
            $min = 0; $max = 0; $avg = 0
        }

        $color = if ($lossPerc -gt 5) { "Red" } elseif ($lossPerc -gt 0) { "Yellow" } else { "Green" }
        $line = "{0,-23} | Потери: {1,5}% ({2}/{3}) | Ping (min/avg/max): {4}/{5}/{6} ms" -f $target, $lossPerc, $lost, $total, $min, $avg, $max
        Write-Host $line -ForegroundColor $color
    }

    Start-Sleep -Seconds 3
}