Port Query (PortQry.exe) is a command-line utility in the Windows operating system that you can use to help troubleshoot TCP/IP connectivity issues. The tool reports the port status of TCP and UDP ports on a computer that you select. In this post, we will show you how to use the Port Query tool for network reconnaissance or forensic activity.
Port Query (PortQry.exe) tool in Windows 11/10
Windows has many tools for diagnosing problems in TCP/IP networks (ping, telnet, pathping, etc.). But not all of them allow you to conveniently check the status or scan opened network ports on a server. The PortQry.exe utility is a convenient tool to check the response of TCP/UDP ports on hosts to diagnose issues related to the operation of various network services and firewalls in TCP/IP networks. Most often, the Portqry utility is used as a more functional replacement for telnet command, and unlike telnet, it also allows you to check open UDP ports.
Computer systems use TCP and UDP for most of their communication, and all versions of Windows open many ports that provide useful functionality such as file sharing and remote procedure call (RPC). However, malicious programs such as Trojan horses can use ports nefariously to open a back door for attackers into your computer system. Whether you need to troubleshoot a necessary network service or detect unwanted programs, you need to be able to understand and manage the traffic between computers on your network. A basic step toward doing so is determining which programs are listening on your computer systems’ network ports.
How to use Port Query Tool (PortQry.exe)
You can use Port Query both locally and remotely on a server. To use Portqry.exe, you will need to download the tool. Once you download PortQry.exe, extract the PortQryV2.exe archive, then open command prompt and run the command below to go to the directory with the utility:
Alternatively, you can navigate to the folder where you downloaded the tool to, and press Alt + D key combo, type CMD and hit Enter to launch command prompt within the directory.
You can now proceed to use the tool.
Remotely use Port Query (PortQry.exe) tool
Port Query can scan remote systems, but it’s slow and unsophisticated compared with other port scanners. For example, unlike Nmap, PortQry.exe doesn’t let you perform scans that use specified packet flags (e.g., SYN, FIN).
For example, to check the availability of a DNS server from a client, you need to check if 53 TCP and UDP ports are open on it. The syntax of the port check command is as follows:
PortQry -n server [-p protocol] [-e || -r || -o endpoint(s)]
- -n is the name or IP address of the server, which availability you are checking;
- -e is the port number to be checked (from 1 to 65535);
- -r is the range of ports to be checked (for example, 1:80);
- -p is the protocol used for checking. It may be TCP, UDP or BOTH (TCP is used by default).
In our example, the command looks like this:
PortQry.exe –n 10.0.25.6 -p both -e 53
PortQry.exe can query a single port, an ordered list of ports, or a sequential range of ports. PortQry.exe reports the status of a TCP/IP port in one of the following three ways:
- Listening: A process is listening on the port on the computer that you selected. Portqry.exe received a response from the port.
- Not Listening: No process is listening on the target port on the target system. Portqry.exe received an Internet Control Message Protocol (ICMP) “Destination Unreachable – Port Unreachable” message back from the target UDP port. Or if the target port is a TCP port, Portqry received a TCP acknowledgment packet with the Reset flag set.
- Filtered: The port on the computer that you selected is being filtered. Portqry.exe did not receive a response from the port. A process may or may not be listening on the port. By default, TCP ports are queried three times, and UDP ports are queried one time before a report indicates that the port is filtered.
Locally use Port Query (PortQry.exe) tool
What PortQry lacks in remote scanning features it makes up for with its unique local-machine capabilities. To enable local mode, run PortQry with the -local switch. When -local is the only switch used, PortQry enumerates all local port usage and port-to-PID mapping. Instead of sorting the data by open port, PortQry lists it according to PID, letting you quickly see which applications have open network connections.
To watch port 80, you’d run the command below:
portqry -local -wport 80
It’s also worth mentioning that Microsoft also made available a graphical front end to PortQry, called PortQryUI.
PortQryUI includes a version of portqry.exe and some predefined services, which consist simply of groups of ports to scan.
The PortQueryUI contains several predefined sets of queries to check the availability of the popular Microsoft services:
- Domain and trusts (checking ADDS services on an Active Directory domain controller)
- Exchange Server
- SQL Server
- IP Sec
- Web Server
- Net Meeting
To use the PortQryUI, enter the DNS name or IP address of the remote server, select one of the predefined services (Query predefined service), or specify the port numbers for manual port check (Manually input query ports) and click the Query button.
Possible return codes in PortQueryUI is highlighted in the image above:
- 0 (0x00000000) – the connection has been established successfully and the port is available.
- 1 (0x00000001) – the specified port is unavailable or filtered.
- 2 (0x00000002) – a normal return code when checking the availability of a UDP connection, since ACK response is not returned.
Hope this helps.
Read next: How to check what Ports are open?