Friday, August 19, 2011

How to hunt down applications via their port numbers

Let’s say that we are looking for port 80 — IIS, Apache and other web servers listen in port 80, so when you are having problems starting Apache, this technique will be useful. Here is the command.
C:\>netstat -aon | findstr 0.0:80
-a means list all active connections and their ports. -o means include their process IDs. -n means display the port numbers numerically.
The pipe symbol ( | ) means, that instead of the result of netstat being displayed on the screen, feed it’s result to the findstr process — we are looking specifically for the line which has 0.0:80 — you actually don’t need findstr, but I don’t want to scroll down and hunt down manually which app is using port 80. You might see something like this.
TCP 0.0.0.0:80 0.0.0.0:0 LISTENING 560
Aha! now we know that process 560 is using port 80 (that last column right there, is the process ID), you could press CTRL-ALT-DEL now to show the process window, and manually look up which app has the process ID 560, or you could enter ..
C:\>tasklist | findstr 560
tasklist is another Windows command line utility which shows you a list of all active processes, again I’d feed it to the findstr utility via the pipe operator, and voila — Skype is the culprit.