PowerShell provides different commands in order to test remote ports whether they are open or closed. The open ports accept the connection requests but closed ports do not return any answer. In this tutorial, we examine different commands in order to check remote port connectivity. Keep in mind that the TCP protocol is used for all of these port connectivity tests.
Test Port with Test-NetConnection Command
PowerShell provides the
Test-NEtConnection command in order to check the remote port. The remote system can be specified as an IP address or hostname and the port number is specified with the
-Port option. In the following example, we check the remote system port 80.
PS> Test-NetConnection google.com -port 80
ComputerName : google.com RemoteAddress : 126.96.36.199 RemotePort : 80 InterfaceAlias : Ethernet0 SourceAddress : 192.168.31.140 TcpTestSucceeded : True
Test Port with Test-Connection Command
Test-Connection command can be also used to check remote port connectivity. The
-Port option is used to specify the remote port. Be aware that this feature is available for PowerShell 6.0 and later.
PS> Test-Connection google.com -port 80
Test Port with tnc Command
tnc command is an alias to the
Test-NEtworkConnection cmdlet. We can provide the remote server hostname or IP address after the tnc command by providing the port number with the
-port option. In the following example, we test the remote server TCP port 80.
PS> tnc google.com -port 80