How to Find Out Which Process Is Listening on a Port on Windows

How to Find Out Which Process Is Listening on a Port on Windows
Photo by Sigmund / Unsplash

Here is how to find out who is listening on a given port number on Windows (Server).

The Interactive Way

First command

netstat -ano | findstr ":443" | findstr "LISTENING"

This reveals the process ID (PID)

Output

  TCP         0.0.0.0:443            0.0.0.0:0              LISTENING       20220
  TCP         [::]:443               [::]:0                 LISTENING       20220

Second command

tasklist /fi "PID eq 20220"

Output

Image Name                     PID Session Name     Session#    Mem Usage
========================= ======== ================ =========== ============
node.exe                     20220 RDP-Tcp#0                  1    122,148 K
PS C:\Users\ml>


This tells you who that process is

The One-Shot Way

Paste the following into PowerShell,
and you will see who is listening on the specified port—both the PID and its identity.

# Script for Windows PowerShell

# Show which process is listening on a given port number


# Specify the port number (change as needed)
$port = 443

# Find processes listening on the specified port
$connections = netstat -ano | Select-String ":$port\s+.*LISTENING"
if (-not $connections) { 
    Write-Host "No process is listening on port $port" 
    exit 
}

# Show connection info
Write-Host "Connection info:"
$connections

# Extract unique process IDs and remove duplicates
$processIds = @{}
$connections | ForEach-Object {
    $processId = $_.ToString().Trim() -replace '.*LISTENING\s+(\d+)', '$1'
    $processIds[$processId] = $true
}

# Show process info (no duplicates)
Write-Host "`nProcess info:"
$processIds.Keys | ForEach-Object {
    Get-Process -Id $_ | Select-Object Id, ProcessName, Path
    Write-Host "To stop this process: taskkill /PID $_ /F" -ForegroundColor Yellow
}

Output

To stop this process: taskkill /PID 20220 /F
   Id ProcessName Path
   -- ----------- ----
20220 node        C:\Program Files\nodejs\node.exe

It shows the PID and process name, along with a hint on how to stop that process.

Happy process managing!

Read more