Netstat

If you have heaps of things running locally in docker containers, node mocks and other development realted things you may run into port clashes. Often after I close a console running a node mock it still hangs around -_-

I use netstat which should be installed with Windows to identify used ports and then kill the process.

Port Known

When the process is running on port 53 you can filter in powershell by piping the response into Select-String. You could the pipe this into taskkill but that doesnt feel smart and Id rather do it manually.

1
netstat -ano | Select-String "53"

Note that the above would also match on any PID matching 53.

Search Port Unknown

1
netstat -a -n -o

What do those switches mean?

  • -a displays all connections, including those that are listening for incoming connections.
  • -n displays the IP addresses and port numbers in numerical form, rather than trying to resolve them to hostnames.
  • -o displays the process ID (PID) of the process that created each connection.

Example response

1
2
3
4
5
Active Connections

Proto Local Address Foreign Address State PID
TCP 0.0.0.0:22 0.0.0.0:0 LISTENING 7860
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING 1908

Kill process by PID

Take the PID from the responses above and pass it below.

1
2
3
taskkill /PID 7860 /F

SUCCESS: The process with PID 5688 has been terminated.

References