1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
foreach($port in 134..142) { try { $tcpobject = New-Object System.Net.Sockets.TcpClient $connect = $tcpobject.BeginConnect("127.0.0.1",$port,$null,$null) # wait for the connection no longer than $timeoutMilliseconds $wait = $connect.AsyncWaitHandle.WaitOne($timeoutMilliseconds,$false) $tcpobject.EndConnect($connect) Write-Host ("Puerto " + $port + " abierto") } catch { Write-Host ("Puerto " + $port + " cerrado") } } |