How to find process id and name listening on TCP/UDP ports in windows


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

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

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

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

nestat command to get process id

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

This command lists following information

  • protocol like TCP or UDP

  • Local address

  • Foreign Address

  • State like LISTENING,ESTABLISHED,TIME_WAIT

  • Process ID

    Here is an 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 symbole with 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 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 process name for 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 command find out process id for 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 90,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts