One line in powershell to check if remote port is open

Here is an easy way to use powershell to see if a remote machine is listening on a specific port. If the command finishes without returning anything the remote machine is listening on the port. If the commands times out or return an error the machine does not listen on that port or your request was blocked by an firewall or ACL rule.

Code:

#Check TCP connection
(New-Object Net.Sockets.TcpClient).Connect("<remote machine>",<port>)

#Check UDP conection
(New-Object Net.Sockets.UdpClient).Connect("<remote machine>",<port>)
This entry was posted in Scripting and tagged , , , , , , , , , , , . Bookmark the permalink.

One Response to One line in powershell to check if remote port is open

Leave a Reply

Your email address will not be published. Required fields are marked *