[CmdletBinding()] param() $ErrorActionPreference = 'Stop' $key = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Internet Settings' $settings = Get-ItemProperty -Path $key -ErrorAction SilentlyContinue $proxyEnable = 0 $proxyServer = '' $autoConfig = '' if ($settings) { $proxyEnable = [int]$settings.ProxyEnable $proxyServer = [string]$settings.ProxyServer $autoConfig = [string]$settings.AutoConfigURL } [pscustomobject]@{ ProxyEnable = $proxyEnable ProxyServer = $(if ($proxyServer) { $proxyServer } else { 'не задан' }) AutoConfigURL = $(if ($autoConfig) { $autoConfig } else { 'не задан' }) } | Format-List $envRows = @() foreach ($name in @('HTTP_PROXY', 'HTTPS_PROXY', 'NO_PROXY', 'ALL_PROXY')) { $value = [Environment]::GetEnvironmentVariable($name) if ($value) { $envRows += [pscustomobject]@{ Переменная = $name; Значение = $value } } } if ($envRows.Count -gt 0) { $envRows | Format-Table -AutoSize } else { Write-Host "Переменные прокси не заданы" } Write-Host "WinHTTP:" & netsh.exe winhttp show proxy 2>&1 | ForEach-Object { Write-Host $_ } if ($proxyServer) { $parts = $proxyServer -split ';' foreach ($part in $parts) { $endpoint = ($part -split '=', 2)[-1].Trim() if ($endpoint -match '^([^:]+):(\d+)$') { $proxyHost = $matches[1] $proxyPort = [int]$matches[2] $client = New-Object System.Net.Sockets.TcpClient try { $async = $client.BeginConnect($proxyHost, $proxyPort, $null, $null) if ($async.AsyncWaitHandle.WaitOne(1500)) { $client.EndConnect($async) Write-Host "Прокси $endpoint доступен" } else { Write-Host "Прокси $endpoint не отвечает" } } catch { Write-Host "Прокси $endpoint недоступен: $($_.Exception.Message)" } finally { $client.Close() } } } }