{

How to find process id name listen to TCP/UDP ports in windows


find process id name listen TCP/UDP ports in windows

In Windows, Every software or tool has one or multiple processes with dependencies.

For example, If you installed apache tomcat on windows, start the server, It listens on the 8080 port by default.

Sometimes, if any process runs on the same port number, You will get an error 8080 is already in use, Please try different ports

This post covers ways to check process id and name details for a given port

nestat command to get the process id

netstat command list out all process and type of connection, process id as well as the hostname

This command lists the following information

  • protocol like TCP or UDP

  • Local address

  • Foreign Address

  • State like LISTENING, ESTABLISHED, TIME_WAIT

  • Process ID

    Here is a command to know the process id and protocol type

C:\>netstat -aon

Active Connections

  Proto  Local Address          Foreign Address        State           PID
  TCP    0.0.0.0:80             0.0.0.0:0              LISTENING       4
  TCP    127.0.0.1:3003         0.0.0.0:0              LISTENING       3852
  TCP    192.168.29.53:31106    116.202.172.174:443    ESTABLISHED     2268
  TCP    [::]:80                [::]:0                 LISTENING       4 
  UDP    0.0.0.0:3702           *:*                                    6100
  

From the above result, you can filter data using pipe symbol with the findStr function

C:\>netstat -ano | findStr "3000"
  TCP    0.0.0.0:3000           0.0.0.0:0              LISTENING       16876
  TCP    [::]:3000              [::]:0                 LISTENING       16876

Another way, if you know the process id, you can use the tasklist command as seen below

The following find out process id is using which port

C:\>tasklist /fi "pid eq 16876"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
node.exe                     16876 Console                    1     78,472 K

Find out Process name and id using PowerShell in windows

PowerShell is a powerful command-line tool to know process details

The below command finds out the process name for the given port

PS C:\> Get-Process -Id (Get-NetTCPConnection -LocalPort 3002).OwningProcess

Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
-------  ------    -----      -----     ------     --  -- -----------
    281      68   127908      98768      12.64  18548   1 node

below the command find out the process id for the given port number


PS C:\> Get-NetTCPConnection -LocalPort 3002| Format-List


LocalAddress   : 0.0.0.0
LocalPort      : 3002
RemoteAddress  : 0.0.0.0
RemotePort     : 0
State: Listen
AppliedSetting :
OwningProcess: 18548
CreationTime   : 29-04-2021 12:47:28
OffloadState   : InHost
THE BEST NEWSLETTER ANYWHERE
Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
Subscribe
You'll get a notification every time a post gets published here.