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.

2 Responses to One line in powershell to check if remote port is open

  1. Vidhya says:

    Thanks so much! Such a life saver for quick troubleshooting!

Leave a Reply

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