Testing open ports with PowerShell

PowerShell is an advanced form of command prompt. It is extended with a huge set of ready-to-use cmdlets and comes with the ability to use .NET framework/C# in various scenarios. If you have the skill to write scripts, you can create some very powerful ones to automate Windows.

One of its cmdlets, Test-NetConnection, can be used to check the connection to a remote address and to a custom port specified by the user.

It has the following syntax:

Test-NetConnection -ComputerName COMPUTER_NAME -Port PORT_NUMBER

Use it as follows.

Test remote network port connection in Windows 10

  1. Open PowerShell
  2. Type the following command:Test-NetConnection -ComputerName COMPUTER_NAME -Port PORT_NUMBERReplace the COMPUTER_NAME portion with the actual remote PC name or IP address. Specify the port you need to connect to instead of the PORT_NUMBER portion.

For example, let’s test the connection to the DNS port (53) of the public Google DNS server (8.8.8.8). The command will look as follows:

Test-NetConnection -ComputerName 8.8.8.8 -Port 53

The output:The line TcpTestSucceeded: True indicates that the connection was successful and the port 53 is open.

If you try to connect to some random port, which is closed for incoming connections, the Test-NetConnection cmdlet will respond with the following information:

The output indicates that the connection has failed. The line TcpTestSucceeded has the value “False”, but the cmdlet shows additional information that the target server is alive. It pinged the destination address and includes the results in the output. See the lines:

PingSucceeded          : True
PingReplyDetails (RTT) : 48 ms

For some servers, you may face the situation where PingSucceeded is False but TcpTestSucceeded is True. It just means that ICMP Ping is disabled on the target server but the destination port is open for incoming connections.

Leave a Reply

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