Sometimes you get the need to know what programs are listening or bound to a particular port on Windows. For me, the most frequent scenario is this: I install WampServer on a PC hoping to use Apache as a web server only to discover that Apache cannot start.
After wondering (a little stupidly at times) why, I resort to check Apache’s logs and discover that the service isn’t starting because it can’t bind to port 80. Implication, some other program got there first! (Well, not really. Just that the other program was installed first)
Most times, I’d just open up the Apache server config file and change the port which it binds to. Some other times, I’d need to identify the offending program and change the port. At a point in the past, if Skype was installed on Windows, you’d need to instruct Skype to use another port (after maybe spending a whole afternoon wondering why Apache won’t start) as it listens for incoming connections on port 80.
Then comes the hard part: How do I know what program is listening on what port?
It turns out it’s fairly easy. As this StackOverflow Answer points out, running this command: C:\> netstat -a -b should do. More from the answer:
(add -n to stop it trying to resolve hostnames, which will make it a lot faster)
-a Displays all connections and listening ports.
-b Displays the executable involved in creating each connection or listening port. In some cases well-known executables host multiple independent components, and in these cases the sequence of components involved in creating the connection or listening port is displayed. In this case the executable name is in  at the bottom, on top is the component it called, and so forth until TCP/IP was reached. Note that this option can be time-consuming and will fail unless you have sufficient permissions. -n Displays addresses and port numbers in numerical form.
Running this command with the
-b option might require administrative privileges as I discovered on my computer.
To get the Process Identified (PID) of the of the process making use of any port, execute the command with the
-o option like this:
C:\>netstat -a -o or like this
This would show you the PID which you can use to look for the “offending” program or process in the Windows Task Manager.
If you’d rather use a GUI (or you’re not that much of a command-line person), you could use these tools which I found during the course of my search:
- TCPView – https://technet.microsoft.com/en-us/sysinternals/bb897437
- CurrPorts by NirSoft – http://www.nirsoft.net/utils/cports.html