Article ID: 310513 - View products that this article applies to.
This article was previously published under Q310513
This article describes how to make Portqry.exe report only ports that are listening and not report ports that are in other states.
Note Version 2 of Portqry.exe is now available. The Microsoft Download Center link at the end of this article has been updated to reflect the new version. Version 1.0 of Portqry.exe has been removed from the Microsoft Download Center.
You can use the Portqry.exe command-line tool to help troubleshoot TCP/IP connectivity issues. Portqry.exe runs on Windows 2000 and later Microsoft Windows operating systems. Portqry.exe reports the port status of target TCP and UDP ports on a computer you select. By default, Portqry.exe reports the status of a port as LISTENING, NOT LISTENING, or FILTERED. When you use the -q (quiet) switch with Portqry.exe, all output to the screen (except error messages) is suppressed. After the target port is queried, Portqry.exe returns one of the following values:
Query.bat Defines What Ports to Query and Calls Listen.bat
@echo PortQry is querying TCP ports 25,110,143,53, and 389
@echo It will only report which ports are listening
@FOR %%I IN (25 110 143 53 389) DO CALL listen.bat %%I
Listen.bat Calls Portqry.exe and Passes it the Target PortNOTE: Only the ports that are found listening are reported.
:TopCopy the text of each of the preceding batch files, paste this text into a text file, and then save these files as Query.bat and Listen.bat. Copy these files into the same folder that contains Portqry.exe, and then run Query.bat. Edit the list of ports in the Query.bat file, as well as the protocol that is used and the target server in the Listen.bat file to change the functionality as needed.
@portqry -n myserver.reskit.com -e %1 -p tcp -q
@if errorlevel = 2 goto end
@if errorlevel = 1 goto end
@if errorlevel = 0 goto success
@Echo Port %1 is listening
NOTE: When you use the -q switch with the -l (log file) switch, Portqry.exe overwrites an existing log file with the same name, and does not prompt you for permission to do so.
To Obtain Portqry.exePortqry.exe is available for download from the Microsoft Download Center. To download Portqry.exe, visit the following Microsoft Web site:
http://www.microsoft.com/downloads/details.aspx?familyid=89811747-C74B-4638-A2D5-AC828BDC6983&displaylang=enFor additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.
(http://support.microsoft.com/kb/119591/EN-US/ )How to Obtain Microsoft Support Files from Online Services
Contact us for more help
Connect with Answer Desk for expert help.