PortQry – Simple Command Line Port Scanner

There are many reasons why you may need to use a port scanner to check if a TCP or UDP port is open.  Microsoft has a little known utility called PortQry that allows you to perform basic port scanning from the command line.

You can download PortQry from http://www.microsoft.com/downloads/en/details.aspx?familyid=89811747-c74b-4638-a2d5-ac828bdc6983&displaylang=en

Download the PortQryV2.exe package and run it to extract the PortQry.exe program, EULA and readme file.  I typically copy PortQry.exe to my %SystemRoot% folder so I can run it from any directory.

Here are some examples of how to use PortQry from the command line:

  • portqry -n servername -e 80  –  Queries remote computer servername to check if it’s listening on TCP port 80 (HTTP).
  • portqry -n servername -p UDP -o 37,88,135  –  Queries the remote computer to check if it’s listening on UDP ports 37, 88 and 135.
  • portqry -n  -r 1-1024  –  Queries the IP address to determine if it’s listening on any of the well-known TCP ports.  The output will display each port and whether it’s listening or not listening.
  • portqry -n -r 1:1024 | find “: LISTENING”  –  Same as above, but only lists open ports.

PortQry can also be run in silent mode using the -q switch.  The program exit with a returncode of 0 if listening, 1 if not listening, or 2 if listening or filtered.  This is useful for batch file processing.