Which PID listens on a given port in c#

后端 未结 2 806
慢半拍i
慢半拍i 2020-11-30 09:32

What is the easiest way to get a PID that listens on a given port in C#? Basically, I want to make sure that my service is running and listens on a port I have provided it.

2条回答
  •  隐瞒了意图╮
    2020-11-30 10:07

    check out this project: http://www.codeproject.com/KB/IP/iphlpapi.aspx

    It uses Interop in C# to get to the underlying GetTcpTable Win API function. And therefore can give you the process id you are looking for.

    hope that helps, Alex

提交回复
热议问题