Table of Contents
I was testing an application that was set to use port 8080. The application failed to start up throwing an exception that the port was in use.
To identify the process tying up port 8080, I opened windows command prompt and typed the following command.
netstat -aop tcp
netstat is useful for displaying active connections and ports on which a computer is listening.
Description of parameters used:
a - Displays all TCP and UDP connections and listening ports
o - Displays the owning process ID associated with each connection
p Protocol - Shows connections for the specified protocol. Protocolc can be TCP, UDP, TCPv6, or UDPv6.
After running the command, I got the following results (truncated):
C:\>netstat -aop tcp Active Connections Proto Local Address Foreign Address State PID TCP 0.0.0.0:135 KagsWin7VB_PC:0 LISTENING 720 TCP 0.0.0.0:445 KagsWin7VB_PC:0 LISTENING 4 TCP 0.0.0.0:8080 KagsWin7VB_PC:0 LISTENING 1876 TCP 0.0.0.0:2869 KagsWin7VB_PC:0 LISTENING 4 TCP 0.0.0.0:5357 KagsWin7VB_PC:0 LISTENING 4 C:\>
To avoid the hassle of scrolling when the results are many, we can chain the command with findstr using a pipe (|) symbol. This will search for port (8080) which I am interested in from the results of netstat.
netstat –aop tcp | findstr :8080
This will return only connections that contain the string 8080 as seen in the following result.
C:\>netstat -aop tcp | findstr 554 TCP 0.0.0.0:8080 KagsWin7VB_PC:0 LISTENING 1876 C:\>
To forcefully terminate the process using port 8080, I use taskkill command passing the process ID.
taskkill /F /PID 1876