C# find process id (pid) of client making an UDP/TCP call

1.6k Views Asked by At

I have a server listening for connections on UDP and another on TCP. I need to know what process initiated the connection. Is that possible? I have found multiple solutions, but all imply checking each process for each port, which has a performance issue in my view. Also, when i tried this, i only get the PID of my server application, not the client.

Thank you

1

There are 1 best solutions below

1
On BEST ANSWER

you can try this

netstat -a -n -o | find "1688"

You will get the exact output of the process

 UDP    10.4.112.77:55866      *:*                                    1688
 UDP    127.0.0.1:1900         *:*                                    1688
 UDP    127.0.0.1:55868        *:*                                    1688

Try this for complete process id port and process name.

  1. Open a command prompt window (as Administrator) From "Start\Search box" Enter "cmd" then right-click on "cmd.exe" and select "Run as Administrator"
  2. Enter: netstat -abno
  3. Find the Port that you are listening on under "Local Address"
  4. Look at the process name directly under that.

you can collect the information and then the parse the output

this one stack link might be helping you. Which PID listens on a given port in c#