PowerShell as a TCP-connect port scanner

Now that we have a host in mind, we can learn more about it with this one liner designed to attempt TCP connections to all specified ports:

> 1..1024 | % {echo ((New-Object Net.Sockets.TcpClient).Connect("192.168.63.147", $_)) "Open port - $_"} 2>$null

As you can see, this is just taking the basics we've learned to the next level. 1..1024 defines our port range and pipes the array into %; with each iteration, a TCP client module is brought up to attempt a connection on the port. 2>$null blackholes STDERR; in other words, a returned error means the port isn't open and the response is thrown in the trash. ...

Get Hands-On Penetration Testing on Windows now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.