Test remote port using Powershell


For the Windows users amongst us there is a simple way of testing if a port is open on a remote server.
If the port isn’t open this test will return a simple diagnostic telling you why.

Start Powershell on your PC and execute these commands :

  # Create a TCP client object
PS> $tcp = New-Object System.Net.Sockets.TcpClient

  # Try to connect to the specified port on the server
PS> $tcp.connect( 'vps211', 50000 )
Exception calling "Connect" with "2" argument(s): "No such host is known"

  # port 50000 not open on vps211
PS> $tcp.connect( 'vps211', 50000 )
Exception calling "Connect" with "2" argument(s): "No connection could be made because the target machine actively refused it vps211:50000"

If the connection is successful no message is returned,

PS> $tcp.connect( 'vps211', 22 )

   # Remove the variable before trying another test
   # If a test fails this MUST be done before re-running the test.
PS> remove-variable tcp
Comment on this article using form below. Requires email login only for authentication. HTML forbidden, Markdown only.