Windows provides several built-in command line utilities for checking remote port accessibility. The most commonly used tools are:
- Telnet (needs to be enabled)
- Test-NetConnection (PowerShell)
- PortQry.exe (downloadable from Microsoft)
- Nmap (third-party but powerful)
First ensure Telnet Client is enabled:
dism /online /Enable-Feature /FeatureName:TelnetClient
Basic syntax for port testing:
telnet [hostname or IP] [port]
Example checking web server on port 80:
telnet example.com 80
A blank screen or server response indicates success, while "Could not open connection" means failure.
More modern approach with detailed output:
Test-NetConnection -ComputerName example.com -Port 443
Sample output structure:
ComputerName : example.com RemoteAddress : 93.184.216.34 RemotePort : 443 InterfaceAlias : Ethernet SourceAddress : 192.168.1.100 TcpTestSucceeded : True
For batch testing multiple ports:
$ports = 80,443,22,3389 foreach ($port in $ports) { Test-NetConnection -ComputerName example.com -Port $port -InformationLevel Quiet }
Checking UDP ports (requires PortQry):
portqry -n example.com -e 53 -p UDP
If connections fail:
- Verify remote firewall rules
- Check local firewall settings
- Confirm service is running on remote machine
- Validate network routing between hosts
Basic Nmap command for port scan:
nmap -Pn -p 80,443 example.com
This provides more detailed information including service versions.
When troubleshooting network connectivity or configuring firewalls, checking if a remote port is open is a common task for Windows administrators and developers. This article explores several command-line methods to test port accessibility.
The simplest way to test a remote port is using the built-in telnet client:
telnet [remote_host] [port]
Example:
telnet example.com 80
If the port is open, you'll see either a blank screen or the service banner. If closed, you'll get a connection error.
For more detailed information, PowerShell's Test-NetConnection cmdlet is powerful:
Test-NetConnection -ComputerName [remote_host] -Port [port]
Example:
Test-NetConnection -ComputerName example.com -Port 443
This provides a detailed output including TCP test success, latency, and source/destination addresses.
Microsoft's PortQry provides advanced port scanning capabilities:
PortQry.exe -n [remote_host] -e [port] -p [TCP/UDP]
Example:
PortQry.exe -n example.com -e 3389 -p TCP
This tool can identify filtered ports and provides more detailed status information than basic telnet.
For programmatic checking, you can use this PowerShell script:
$tcp = New-Object System.Net.Sockets.TcpClient try { $tcp.Connect("example.com", 80) Write-Host "Port open" } catch { Write-Host "Port closed" } finally { $tcp.Close() }
Other useful tools include:
- Nmap (requires installation)
- PsPing (from Sysinternals)
- Test-Connection in PowerShell
Remember that a "closed" port might mean:
- The port is actually closed
- A firewall is blocking the connection
- The service isn't running
- Network connectivity issues exist