Windows has quite a few network troubleshooting command-lines out of the box, such as Ping, IPConfig, NSLookup, PathPing, etc. But there is another good one, also provided by Microsoft but not included in Windows by default for some reason, that can do one thing none of the built-in ones can handle, checking the status of the open TCP/UDP ports on a computer you are testing.
Portqry.exe is a command-line network utility that can greatly help you troubleshoot TCP/IP connectivity issues, especially the issues about the open/close ports. It’s been around for more than over 10 years, so it works on systems from Windows 2000 and above, including the latest Windows 7 and 8, both 32-bit and 64-bit systems.
Portqry.exe reports the status of a TCP/IP port in one of the 3 ways:
- Listening – means that the testing port is open, and there is a process is listening on the port right the moment.
- Not Listening – no process is listening on the target port on the target system.
- Filtered – means that the port is being filtered. A process may or may not be listening on the port.
Portqry.exe runs in one of the 3 modes, command-line mode, interactive mode, and local mode. The basic syntax for command-line mode is
portqry -n target [-options]
If no -options present, the command will query port 80 by default on the target machine, see Figure 1.
You can also query a specific port, with the option -p and -e, such as below to query TCP port 21 on our website.
portqry -n nextofwindows.com -p tcp -e 21
And with an option -o, you can query a number of ports in order within one command. The command below is trying to query TCP port 143, 110, and 21 in order (Figure 2).
portqry -n nextofwindows.com -p tcp -o 143,110,21
You can also query a range of ports as well with the option -r, such as below (Figure 3):
portqry -n nextofwindows.com -p tcp -r 25:200
Want to save result, you can use the switch -l to save the result to the specified log file.
Feel boring about the Command Prompt window? The good news is that there is also a GUI version of Portqry.exe called PortQueryUI (direct download link from Microsoft) available on Microsoft Download that has several features that can make your troubleshooting life a lot easier (Figure 4).
For Win 7 (and 8) You need to download and install portqry