$s=@{}; while($true) { $t=Get-Date -Format 'HH:mm:ss'; Write-Host "`n=== ОПРОС УЗЛОВ [$t] ===" -ForegroundColor Cyan; @('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') | % { if(!$s[$_]){$s[$_]=@{Sent=0;Lost=0;Times=@()}} $res=Test-Connection $_ -Count 5 -ErrorAction SilentlyContinue; $s[$_].Sent+=5; if($res){ $lostCount=5-$res.Count; $s[$_].Lost+=$lostCount; $res | % { $s[$_].Times+=$_.ResponseTime }; $curLoss=[math]::Round(($lostCount/5)*100); $avgPing=[math]::Round(($res | Measure-Object ResponseTime -Average).Average); Write-Host "[$t] $_ : Loss = $curLoss% | Avg Ping = $avgPing ms" -ForegroundColor (if($curLoss -gt 0){'Yellow'}else{'Green'}) } else { $s[$_].Lost+=5; Write-Host "[$t] $_ : Loss = 100% | TIMEOUT" -ForegroundColor Red } }; Write-Host "`n================ ОБЩАЯ СТАТИСТИКА ЗА ВСЕ ВРЕМЯ ================" -ForegroundColor Yellow; $s.Keys | Sort-Object | % { $total=$s[$_].Sent; $lost=$s[$_].Lost; $perc=[math]::Round(($lost/$total)*100, 1); $times=$s[$_].Times; if($times.Count -gt 0){ $min=($times | Measure-Object -Minimum).Minimum; $max=($times | Measure-Object -Maximum).Maximum; $avg=[math]::Round(($times | Measure-Object -Average).Average) } else { $min=0; $max=0; $avg=0 }; Write-Host ("{0,-23} | Потери: {1,4}% ({2}/{3}) | Ping min/avg/max: {4}/{5}/{6} ms" -f $_, $perc, $lost, $total, $min, $avg, $max) -ForegroundColor (if($perc -gt 5){'Red'}elseif($perc -gt 0){'Yellow'}else{'Green'}) }; Start-Sleep -Seconds 5 }