1

How to find port on windows (using pid or processes name)

I know the PID, but I need the port on which the processes are running

anand8398
  • 13
  • 3

2 Answers2

0

you can use the following CMD command (Open it as administrator)

 netstat -aon | findstr PID

There more different ways to find process port available here.

Nikita
  • 61
  • 8
  • Thanks for response!!! specifically want only the port of a processes, I know the name and PID of that processes, how to find the port – anand8398 Jan 20 '23 at 22:02
  • You can use this command to find a port used by process: `netstat -aon | findstr PID` Updated initial comment – Nikita Jan 20 '23 at 22:28
  • Thank you so much...... **TCP 0.0.0.0:81 0.0.0.0:0 LISTENING 5424** I am getting this kind of result which is ok, but I want that port only, what to do for it – anand8398 Jan 20 '23 at 22:55
0

The accepted answer to the question that Nikita's answer links to - https://stackoverflow.com/a/48199/45375 - can be adapted to your needs with the following PowerShell command (assumes that the PID of interest is stored in $yourPid):

(Get-NetTCPConnection | Where-Object OwningProcess -eq $yourPid).LocalPort |
  Select-Object -Unique

Note that even weeding out duplicates can result in multiple ports getting returned.

See also:

mklement0
  • 382,024
  • 64
  • 607
  • 775