To find the port number and which service is running in that port

2022-04-23

Sometimes we need to find out what service is running in a port, for example its common that while running the web API application in asp.net core in development environment it sometimes shows that the port 5000 is already in use and cannot run the service in this port as its already used. This cause confusion as dev believes he had stopped the service but still when try to run the application it says the port is already is in use. This is irritating as by default asp.net core runs in 5000(http) & 5001(https)

So to confirm which application is really running in that port we have to check out what is the status of the port and the process ID running in that port

To list the ports

netstat –aon

The -n tells netstat to show the IP addresses and ports as numbers only.
The -a tells it to show us all active connections and the ports on which the computer is listening.
The -o represents process ID

To check a specific port

netstat –aon | find "5000"

this will produce the result as 

C:\windows\system32>netstat -aon | find "5000"
 Proto  Local Address          Foreign Address        State           PID
TCP      127.0.0.1:5000         0.0.0.0:0              LISTENING 16056
TCP      [::1]:5000                  [::]:0                   LISTENING 16056

now go to task manager and find the process ID and kill it.

0 comments: