brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: netstat -ano shows which process ID owns each open port

Network and access
~/tips/tip-windows-netstat-ano-pid

netstat -ano | findstr :8080

Lists connections and listening ports in numeric form with the owning process ID, then tasklist names it.

When a program says a port is already in use, you need to know who has it. netstat has the port and the process ID, and tasklist turns the ID into a name.

netstat -ano | findstr :8080
tasklist /fi "PID eq 4321"

-a shows all connections and the ports that are listening, -n keeps addresses and ports numeric so nothing waits on name lookups, and -o adds the process ID. The findstr in the example filters the output to one port, and the last column of the matching line is the PID.

Then ask tasklist for that PID. Microsoft’s reference lists PID as a valid filter name, so the /fi filter above prints the one process. Add /svc to see which services run inside it, which helps when the process is a generic svchost.exe.

If you prefer to let netstat name the program, netstat -b shows the executable behind each connection, but Microsoft warns it can be time consuming and fails without sufficient permissions.

The caveat is that the output is a snapshot. Connections come and go, and a PID can be reused after a process ends, so look up the PID right after you read it. Reading the port from the end of a line also deserves care, since findstr :80 matches port 8080 too. Search with the full port number and check the local address column.

Further reading: Microsoft Learn: netstat, Microsoft Learn: tasklist

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link