Thursday, December 07, 2006
An Ode to PortQry
Oh PortQry, how I love thee!
I came across this little util back in July and have been using the hell out of it since. It's especially great for testing firewall configs - a quick way to test whether a specific port on a specific IP is listening.
Two things I came across recently that have been useful:
So you can use portqry in another script, not worry about it's output, and just check the resultant errorlevel for the outcome. Kudos to Microsoft for coding it correctly!
I came across this little util back in July and have been using the hell out of it since. It's especially great for testing firewall configs - a quick way to test whether a specific port on a specific IP is listening.
Two things I came across recently that have been useful:
PortQry Return Code
This might be documented someplace, but I found that portqry uses the following return codes:0 = Listening
1 = Not Listening
2 = Filtered
Those are the only three status messages that I've ever seen. An easy way to check the return code from the command line:
C:\Documents and Settings\Aaron>portqry -n www.google.com -e 80
Querying target system called:
www.google.com
Attempting to resolve name to IP address...
Name resolved to 64.233.161.147
querying...
TCP port 80 (http service): LISTENING
C:\Documents and Settings\Aaron>echo %errorlevel%
0
C:\Documents and Settings\Aaron>
So you can use portqry in another script, not worry about it's output, and just check the resultant errorlevel for the outcome. Kudos to Microsoft for coding it correctly!
PortQry Local Mode
A developer came to me today asking on what ports a specific server is listening, specifically the Apache web server. My first thought was to find some app to do a port scan. Then I remembered something from the portqry man entry:portqry -local > portqry.txt
Run that from the server in question, then open portqry.txt. Open Task Mangler and view PIDs. I was then able to match the PIDs and find that Apache was listening on 80, 443 and 3339 - which was the port he wanted. Done and done.