Build netstat and Get-NetTCPConnection commands to find the process using a port and list connections.
netstat (network statistics) lists active TCP/UDP connections, listening ports, the routing table, and per-protocol counters. Its most common job today is answering one question: which process is using a port? This builder generates the right command for Command Prompt or modern PowerShell, where the Get-NetTCPConnection cmdlets have largely replaced the classic tool.
| Flag | Meaning |
|---|---|
-a | Show all connections and listening ports |
-n | Show addresses and ports numerically (no DNS, faster) |
-o | Show the owning process ID (PID) |
-b | Show the owning executable (needs Administrator) |
-r | Show the routing table |
-s | Show per-protocol statistics |
The classic recipe combines netstat -ano with findstr to filter by port, then tasklist to name the PID:
netstat -ano | findstr :3389
tasklist /FI "PID eq 1234"The first command lists every connection on port 3389 with its PID in the last column; the second resolves that PID to a program name. In PowerShell the equivalent is one line:
Get-NetTCPConnection -LocalPort 3389 | Select-Object LocalPort, State, OwningProcessnetstat -anonetstat -ano | findstr LISTENINGnetstat -anob (run as Administrator)netstat -rnetstat -s -p tcpColumns are protocol, local address:port, remote address:port, state, and PID. LISTENING means a server is waiting for connections on that port; ESTABLISHED is an active session; TIME_WAIT is a recently closed connection winding down (normal, not a leak). Always pair -o with a tasklist or Get-Process lookup so a bare PID becomes a real program name.
netstat -ano | findstr :PORT names the culprit so you can stop or reconfigure it.netstat -ano | findstr LISTENING shows every service exposed on the machine, useful for spotting unexpected open ports.netstat -anob reveals which program opened each outbound connection, helping investigate suspicious or unexpected network activity.netstat -r prints the routing table so you can confirm the default gateway and any static routes.-b flag requires an elevated prompt; without it you see only the PID.-n to avoid slow reverse-DNS lookups when you just need numbers.Get-NetTCPConnection cmdlets — they return objects you can sort, filter, and join to Get-Process directly.Run netstat -ano | findstr :PORT to list connections on that port; the process ID is in the last column. Then run tasklist /FI "PID eq NUMBER" to see the program name. In PowerShell, Get-NetTCPConnection -LocalPort PORT does the same in one step.
LISTENING means a service is waiting for connections on that port. ESTABLISHED is an active, open session. TIME_WAIT is a recently closed connection that is winding down, which is normal and clears on its own after a short timeout.
The -b flag reveals the executable that owns each connection, which requires administrator rights. Open Command Prompt or PowerShell as Administrator and run it again, or use -o instead to get just the process ID without elevation.
On modern Windows it is often more convenient. Get-NetTCPConnection returns structured objects you can sort, filter, and pipe directly to Get-Process to resolve the program name, whereas netstat returns plain text you have to parse with findstr and tasklist.