$ErrorActionPreference = 'SilentlyContinue' $ports = @(22,80,443,445,3389,3306,6379,8080,8443,9000,1433,21,139,5900,9200,27017,5985,5986,10000,3000,8000,8888,9090,8161,2083,8081,8082,1080,5432,25,110,993,2375,6443,10250,9200) $ports = $ports | Select-Object -Unique $nets = @('192.168.1.', '10.148.0.') $res = @() foreach ($net in $nets) { foreach ($p in $ports) { $tasks = New-Object System.Collections.ArrayList for ($i = 1; $i -le 254; $i++) { $ip = "$net$i" $c = New-Object System.Net.Sockets.TcpClient $c.NoDelay = $true try { $a = $c.BeginConnect($ip, $p, $null, $null) } catch { continue } [void]$tasks.Add([pscustomobject]@{IP=$ip;Port=$p;C=$c;A=$a}) } Start-Sleep -Milliseconds 900 foreach ($t in $tasks) { try { if ($t.C.Connected) { $res += "$($t.IP):$($t.Port)" } } catch {} try { $t.C.Close() } catch {} } } Write-Output "--- SEGMENT $net done ---" } Write-Output "=== OPEN PORTS ===" if ($res.Count -eq 0) { Write-Output "NONE" } else { $res | Sort-Object -Unique | ForEach-Object { Write-Output $_ } } Write-Output "=== TOTAL $($res.Count) ==="