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
Supposing Telnet is installed on your Windows machine:
- Open a command prompt or a PowerShell
- Execute the following command:
- 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
telnet "remote host" "port"
Where:
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:
- Open a PowerShell
- Execute the following command:
- 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
Test-NetConnection -ComputerName "remote host" -Port "port number"
Where (as in the previous paragraph):
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