SOSysAdmin logo SOSysAdmin


How to test if a port is open on a remote machine

flag Scope

Verifying if a port is open on a remote machine.

construction How-to
There are 2 quick ways to check if a port is open on a remote host:
  • Using Telnet (the old-fashioned way)
  • Using PowerShell
Option 1 – Using Telnet

Supposing Telnet is installed on your Windows machine:
  1. Open a command prompt or a PowerShell
  2. Execute the following command:
  3. telnet "remote host" "port"

    Where:
    • remote host: : the IP or DNS name of the remote machine (Note: you can't specify a protocol, so google.com will work, while https://google.com won't)
    • port: the port number

So, if you want to test the connection to port 443 (HTTPS) on google.com simply run:
telnet google.com 443

There are two possible outcomes:
  • The port is open and you will get an empty prompt awaiting for your input (depending on the service running behind that port)
  • The port is closed/not listening. This will be noticeable by an error message like this:
  • Could not open connection to the host, on port 443: Connection failed

Option 2 – Using Telnet

The modern way to test a connection using the Test-NetConnection cmdlet:
  1. Open a PowerShell
  2. Execute the following command:
  3. Test-NetConnection -ComputerName "remote host" -Port "port number"

    Where (as in the previous paragraph):
    • remote host: : the IP or DNS name of the remote machine (Note: you can't specify a protocol, so google.com will work, while https://google.com won't)
    • port: the port number

So, if you want to test the connection to port 443 (HTTPS) on google.com run:
Test-NetConnection -ComputerName google.com -Port 443

The output will be similar to this:

ComputerName      : google.com
RemoteAddress     : 142.250.184.110
RemotePort        : 443
InterfaceAlias    : Ethernet
SourceAddress     : 192.168.0.1
TcpTestSucceeded  : True
            

You can check the outcome by looking at the last line, TcpTestSucceeded, which can be either true or false.
While it's not the quickest way to test a single port, the Test-NetConnection cmdlet has a lot of other useful options and use cases.
You can find the link to the documentation at the end of this page.

school Further considerations

  • Remember that if you "opened" a port but there isn't a running service listening on that port (example: you allowed incoming packets on port 80 but your NGINX server is not running) it will be reported as closed
  • You can read more about the Test-NetConnection cmdlet on the official Microsoft documentation




Article ID: SYS-WIN-0009