Knowing which process is listening on a TCP or UDP port is crucial for troubleshooting network connectivity issues, managing firewall configurations, or identifying potentially malicious activities.
In this guide, we will explore various methods to determine the process associated with a specific port on a Windows system.
We’ll cover both command-line utilities and programming techniques that can assist in this task.
Method 1: Using Command-Line Tools
Windows provides several built-in command-line tools that can be used to identify the process listening on a TCP or UDP port. Here are the steps to follow:
Step 1: Open Command Prompt or PowerShell
Launch Command Prompt or PowerShell with administrative privileges.
This is necessary to access certain system-level information.
Step 2: Execute the netstat
Command
In the command prompt, enter the following command to retrieve a list of active connections and listening ports:
netstat -ano
This will display a table with the local address, foreign address, state, and process ID (PID) for each active connection or listening port.
Step 3: Identify the PID and Corresponding Process
- Look for the desired port in the “Local Address” column.
- Note the associated PID in the “PID” column.
- Then, open the Task Manager by pressing Ctrl+Shift+Esc and navigate to the “Processes” or “Details” tab.
- Locate the PID in the list to identify the process.
Using netstat
to Find Which Process Is Listening to a TCP or UDP Port (More Examples)
Here are some additional examples of using the netstat
command to find the process associated with TCP and UDP ports:
Example 1: Finding the Process for a Specific TCP Port
To identify the process using a specific TCP port (e.g., port 80), use the following command:
netstat -ano | findstr :80
This command filters the output of netstat
to display only the entries related to port 80. The process ID (PID) and the corresponding process can be identified in the output.
Example 2: Finding the Process for a Specific UDP Port
To determine the process using a specific UDP port (e.g., port 53), execute the following command:
netstat -ano | findstr :53 | findstr /i "udp"
Similar to the previous example, this command filters the netstat
output to show only the entries for port 53 and then further filters for UDP connections.
Example 3: Displaying the Process Name in the Output
If you prefer to see the process name directly in the netstat
output, you can use the /B
flag with the netstat
command.
For example, to display both TCP and UDP ports along with their associated process names, run the following command:
netstat -ano -b
The output will include the process name alongside the process ID (PID).
Note: Ensure that you run the netstat
command with administrative privileges to access all necessary information.
These examples demonstrate how the netstat
command can be utilized to identify the process using specific TCP or UDP ports on Windows.
How to Find UDP listening ports in Windows?
To find UDP listening ports in Windows, you can use various command-line tools and utilities. Here are a few examples:
Example 1: Using the netstat
Command
The netstat
command can be used to display active connections and listening ports on your system. To specifically find UDP listening ports, you can run the following command:
netstat -ano -p udp | findstr "LISTENING"
This command filters the output of netstat
to show only the UDP ports that are in a listening state. The process ID (PID) and the associated process can be identified in the output.
Example 2: Using PowerShell Commands
PowerShell provides more flexible options for retrieving UDP listening ports. Here’s an example using PowerShell commands:
$udpPorts = Get-NetUDPEndpoint | Where-Object { $_.State -eq "Listen" }
if ($udpPorts) {
foreach ($port in $udpPorts) {
$processId = $port.OwningProcess
$process = Get-Process -Id $processId
Write-Host "Process Name: $($process.ProcessName)"
Write-Host "PID: $($process.Id)"
Write-Host "Local Address: $($port.LocalAddress)"
Write-Host "Local Port: $($port.LocalPort)"
Write-Host "State: $($port.State)"
Write-Host "----------"
}
}
else {
Write-Host "No UDP listening ports found."
}
This PowerShell script retrieves all UDP endpoints in a listening state and displays information such as the process name, PID, local address, local port, and state for each listening port.
Example 3: Using the Resource Monitor
Windows Resource Monitor provides a graphical interface to monitor system resources, including network activity. To find UDP listening ports using Resource Monitor:
- Press the Windows key + R to open the Run dialog box.
- Type “
resmon
” and press Enter to open Resource Monitor. - In Resource Monitor, navigate to the “Network” tab.
- Under the “Listening Ports” section, locate the “UDP” column to find the UDP listening ports. The corresponding processes and other details are displayed alongside.
These examples demonstrate different approaches to finding UDP listening ports in Windows, using the netstat command, PowerShell commands, and the Resource Monitor.
How to Check if UDP Port is Listening?
To test UDP port listening in Windows, you can use various programming languages or utilities to send UDP packets and check for a response.
Here are examples using Python and PowerShell:
Example 1: Testing UDP Port Listening with Python
Using Python’s socket
module, you can create a UDP socket and attempt to send a packet to the desired port.
If the port is open and actively listening, you should receive a response.
Here’s an example Python code snippet:
import socket
def test_udp_port(host, port):
try:
udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
udp_socket.settimeout(2) # Set a timeout for the response
udp_socket.sendto(b"Test", (host, port))
data, address = udp_socket.recvfrom(1024)
print(f"UDP port {port} is open and responsive.")
except socket.timeout:
print(f"UDP port {port} is open but did not respond.")
except ConnectionRefusedError:
print(f"UDP port {port} is closed.")
# Example usage: Testing UDP port 1234 on localhost
test_udp_port("localhost", 1234)
In this example, we create a UDP socket, set a timeout for the response, and attempt to send a UDP packet with the “Test” message to the specified host and port.
If a response is received within the timeout, it indicates that the UDP port is open and actively listening.
Example 2: Testing UDP Port Listening with PowerShell
PowerShell provides the Test-NetConnection
cmdlet, which can be used to test network connectivity, including UDP port listening.
Here’s an example PowerShell code snippet:
$port = 1234 # Replace with the desired UDP port number
$result = Test-NetConnection -ComputerName localhost -Port $port -InformationLevel Quiet
if ($result) {
Write-Host "UDP port $port is open and listening."
}
else {
Write-Host "UDP port $port is closed."
}
In this example, we use the Test-NetConnection
cmdlet to test the connection to the specified UDP port. If the UDP port is open and actively listening, the result will be true, indicating a successful connection.
These code examples demonstrate how to test UDP port listening in Windows using Python and PowerShell.
Method 2: Using PowerShell Commands
PowerShell provides more flexible and scriptable methods to identify the process listening on a port.
Here’s an example using PowerShell commands:
$port = 8080 # Replace with your desired port number
$listener = Get-NetTCPConnection -LocalPort $port -ErrorAction SilentlyContinue
if ($listener) {
$processId = $listener.OwningProcess
$process = Get-Process -Id $processId
Write-Host "Process Name: $($process.ProcessName)"
Write-Host "PID: $($process.Id)"
}
else {
Write-Host "No process is currently listening on port $port."
}
Method 3: Writing a Custom Program (C#)
If you prefer a programmatic approach, you can use a programming language like C# to identify the process listening on a specific port. Here’s an example using C#:
using System;
using System.Net;
using System.Net.NetworkInformation;
class Program
{
static void Main()
{
int port = 8080; // Replace with your desired port number
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] endpoints = properties.GetActiveTcpListeners();
foreach (IPEndPoint endpoint in endpoints)
{
if (endpoint.Port == port)
{
TcpConnectionInformation connection = properties.GetActiveTcpConnections()
.FirstOrDefault(c => c.LocalEndPoint.Equals(endpoint));
if (connection != null)
{
int processId = connection.ProcessId;
string processName = Process.GetProcessById(processId).ProcessName;
Console.WriteLine("Process Name: " + processName);
Console.WriteLine("PID: " + processId);
return;
}
}
}
Console.WriteLine("No process is currently listening on port " + port);
}
}
Wrapping Up
By following the methods outlined in this guide, you can easily determine the process associated with a specific TCP or UDP port on a Windows system.
Whether you choose to use built-in command-line tools or leverage PowerShell or a custom program, having this knowledge will empower you to diagnose network-related issues and maintain a secure environment.

Abhinav worked as a software engineer at numerous startups and large enterprises for over 12 years. He has worked on a variety of projects, from developing software to designing hardware. He is passionate about tinkering with computers and learning new things. He is always looking for new ways to use technology to solve problems and make people’s lives easier. That is the inspiration behind https://foxrunsoftware.net. Abhinav created FoxRunSoftware to address common errors and issues faced by engineers and non-engineers alike!