process
UDP
TCP
coding
windows

Find which process is listening on a TCP or UDP port on Windows

Codemia Knowledge Hub ·

Run netstat -aon filtered with findstr to get the PID that owns the port, then look up that PID with tasklist. PowerShell's Get-NetTCPConnection and Get-NetUDPEndpoint do the same with structured output, and Resource Monitor or Sysinternals TCPView show it graphically. This is the quickest fix for a "port already in use" error when starting a development server.

netstat and tasklist in Command Prompt

netstat is available on every Windows version. To find what is listening on TCP port 8080:

cmd
netstat -aon -p tcp | findstr :8080

Typical output:

text
  TCP    0.0.0.0:8080           0.0.0.0:0              LISTENING       12456
FlagMeaning
-aShow all connections and listening ports
-oShow the owning PID for each connection
-nShow addresses and ports numerically (no DNS lookups)
-p tcpFilter to TCP over IPv4 only (use -p tcpv6 for IPv6)

Without -o there is no PID column, so always include it. The last column (12456) is the PID. Look up the process name:

cmd
tasklist /FI "PID eq 12456"

Output:

text
Image Name                     PID Session Name        Mem Usage
========================= ======== ================ ============
node.exe                     12456 Console            85,432 K

So node.exe (PID 12456) is listening on port 8080.

One-liner

Chain the two commands to pass the PID straight to tasklist:

cmd
for /f "tokens=5" %a in ('netstat -aon -p tcp ^| findstr :8080 ^| findstr LISTENING') do @tasklist /FI "PID eq %a" /NH

In a batch file, double the % signs:

cmd
for /f "tokens=5" %%a in ('netstat -aon -p tcp ^| findstr :8080 ^| findstr LISTENING') do @tasklist /FI "PID eq %%a" /NH

Matching the exact port with findstr

Searching for :80 also matches :8080, :8000 and any other port containing 80. Use findstr " :80 " with spaces or findstr /R ":80[^0-9]" for more precise matching.

PowerShell cmdlets (better for scripting)

PowerShell returns objects instead of text, so there is nothing to parse.

TCP port owner

powershell
Get-NetTCPConnection -LocalPort 8080 -State Listen |
    Select-Object LocalAddress, LocalPort, OwningProcess,
        @{Name='ProcessName'; Expression={(Get-Process -Id $_.OwningProcess).ProcessName}}

Sample output:

text
1LocalAddress LocalPort OwningProcess ProcessName
2------------ --------- ------------- -----------
3::           8080      12456         node
40.0.0.0      8080      12456         node

UDP port owner

UDP is connectionless and has no LISTENING state, so query bound endpoints instead:

powershell
Get-NetUDPEndpoint -LocalPort 5353 |
    Select-Object LocalAddress, LocalPort, OwningProcess,
        @{Name='ProcessName'; Expression={(Get-Process -Id $_.OwningProcess).ProcessName}}

All listening ports

powershell
1Get-NetTCPConnection -State Listen |
2    Sort-Object LocalPort |
3    Select-Object LocalPort, OwningProcess,
4        @{Name='ProcessName'; Expression={(Get-Process -Id $_.OwningProcess).ProcessName}} |
5    Format-Table -AutoSize

Stopping the process

Once you have the PID:

powershell
1# Check what you are about to stop
2Get-Process -Id 12456
3
4# Stop it
5Stop-Process -Id 12456 -Force

Or in one line:

powershell
Get-NetTCPConnection -LocalPort 8080 -State Listen |
    ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }

Be careful with this, especially on production systems, and confirm the process name before killing it.

Resource Monitor and TCPView

Resource Monitor (built in)

  1. Press Win + R, type resmon, and press Enter
  2. Navigate to the Network tab
  3. Expand the Listening Ports section
  4. Find your port number and read the associated image name and PID

Resource Monitor also shows network activity per process, which helps when you need more context than the port binding.

TCPView (Sysinternals)

TCPView from Microsoft's Sysinternals suite gives a live, sortable view of all TCP and UDP endpoints. It updates in real time and can close connections or kill processes from the UI. Download it from the Sysinternals website or install it with winget:

cmd
winget install Microsoft.Sysinternals.TCPView

Sorting by port number shows every owner at once, which makes it handy for investigating conflicts interactively.

When the owner is svchost.exe

svchost.exe is a generic host for Windows services, and one instance can run several services, so the PID alone does not identify the culprit. List the services in that process:

powershell
# Find services running in a specific svchost instance
Get-WmiObject Win32_Service | Where-Object { $_.ProcessId -eq 12456 } |
    Select-Object Name, DisplayName, State

Or from Command Prompt:

cmd
tasklist /SVC /FI "PID eq 12456"

Common examples:

PortServiceDescription
80W3SVCIIS Web Server
135RpcSsRPC Endpoint Mapper
445LanmanServerSMB File Sharing
5040CDPSvcConnected Devices Platform

TCP vs UDP output

AspectTCPUDP
Shows LISTENING stateYesNo (UDP is connectionless)
netstat flag-p tcp-p udp
PowerShell cmdletGet-NetTCPConnectionGet-NetUDPEndpoint
State filtering-State ListenNot applicable
Common ports80, 443, 8080, 330653 (DNS), 5353 (mDNS), 67 (DHCP)

A UDP row without LISTENING does not mean the port is free. UDP has no connection state, so if netstat shows a UDP row with your port, something is bound to it.

Running as Administrator

Some system processes and services can only be inspected with elevated privileges. If output looks incomplete, or the PID column shows 0 or blanks, rerun from an elevated Command Prompt (right-click CMD, then Run as administrator):

cmd
1:: Run Command Prompt as Administrator
2:: Right-click CMD > Run as administrator
3
4netstat -aon -p tcp | findstr :443

In PowerShell, start an elevated session:

powershell
Start-Process powershell -Verb RunAs

Elevation is not always needed, but it avoids false negatives that waste debugging time.

Quick reference

cmd
1:: Find what is using port 3000 (typical React dev server)
2netstat -aon -p tcp | findstr :3000
3
4:: Find what is using port 5432 (PostgreSQL)
5netstat -aon -p tcp | findstr :5432
6
7:: Check if port 443 is in use (HTTPS)
8netstat -aon -p tcp | findstr :443
9
10:: Find all listening ports
11netstat -aon -p tcp | findstr LISTENING
powershell
1# PowerShell equivalents
2Get-NetTCPConnection -LocalPort 3000 -State Listen
3Get-NetTCPConnection -LocalPort 5432 -State Listen
4Get-NetTCPConnection -LocalPort 443 -State Listen
5Get-NetTCPConnection -State Listen | Sort-Object LocalPort

Note that the flags differ from Linux, where netstat uses -tulpn. On Windows use -aon -p tcp; the two are not interchangeable.


Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design