$IPFilePath = "C:\tools\ips.txt"
$OutputFile = "C:\tools\rdp_available.txt"
$Port = 3389
$Timeout = 3000
if (Test-Path $OutputFile) { Remove-Item $OutputFile }
if (-not (Test-Path $IPFilePath)) {
Write-Host "Файл $IPFilePath не найден!" -ForegroundColor Red
Read-Host "Нажмите Enter для выхода..."
exit
}
$IPList = Get-Content $IPFilePath | ForEach-Object { $_.Trim() } | Where-Object { $_ -ne "" -and $_ -notmatch "^#" }
if ($IPList.Count -eq 0) {
Write-Host "Список IP пуст или не прочитан." -ForegroundColor Yellow
Read-Host "Нажмите Enter для выхода..."
exit
}
Write-Host "Проверка доступности RDP (порт $Port) для $($IPList.Count) хостов...`n" -ForegroundColor Cyan
$AvailableIPs = @()
foreach ($IP in $IPList) {
$client = New-Object System.Net.Sockets.TcpClient
$connect = $client.BeginConnect($IP, $Port, $null, $null)
$wait = $connect.AsyncWaitHandle.WaitOne($Timeout, $false)
if (!$wait) {
Write-Host "$IP`: ❌ Недоступен (таймаут)" -ForegroundColor Red
$client.Close()
continue
}
try {
$client.EndConnect($connect)
Write-Host "$IP`: ✅ Доступен по RDP" -ForegroundColor Green
$AvailableIPs += $IP
} catch {
Write-Host "$IP`: ❌ Недоступен (ошибка подключения)" -ForegroundColor Red
}
$client.Close()
}
if ($AvailableIPs.Count -gt 0) {
$AvailableIPs | Out-File -Encoding UTF8 -FilePath $OutputFile
Write-Host "`n✅ Доступные RDP-хосты сохранены в: $OutputFile" -ForegroundColor Green
$runRDPSS = Read-Host "Запустить RDPSS для доступных хостов? (y/n)"
if ($runRDPSS -match "^[yY]") {
foreach ($ip in $AvailableIPs) {
Write-Host "Запуск RDPSS для $ip"
Start-Process "rdpss.exe" -ArgumentList $ip -WorkingDirectory "C:\Путь\к\RDPSS\"
Start-Sleep -Milliseconds 500
}
}
} else {
Write-Host "`n❌ Ни один хост не доступен по RDP." -ForegroundColor Red
}
Write-Host "`nГотово. Нажмите Enter для выхода..." -ForegroundColor Cyan
Read-Host