Curtis
Curtis

Reputation: 5892

Using C# in .net on a windows machine, is there a way to determine what tcp or udp ports a particular app is using or has opened?

My app opens random ports from time to time and uses them. I've seen a problem where over a long period of time, there is a resource leak.

Is there a way to programatically get a list of open TCP and UDP ports that my current app is using? I need this information for the currently running app, not for external apps.

Any ideas of how to get a list of open ports without having to just check each port one by one to see if they're opened?

Upvotes: 0

Views: 74

Answers (1)

Idov
Idov

Reputation: 5124

You can use this:
https://code.msdn.microsoft.com/windowsdesktop/C-Sample-to-list-all-the-4817b58f

and take the ports associated with your PID.

Upvotes: 2

Related Questions