问题描述
我想知道如果一个特定的进程正在使用指定端口,即 netstat的-ban
。我碰到使用 IPGlobalProperties
来获得活动连接的列表中,但是这似乎并没有包含过程信息。
I'd like to know if a particular process is using a given port, i.e. netstat -ban
. I came across using IPGlobalProperties
to get the list of active connections, but this doesn't seem to include process information.
这将是很好,如果存在某个类在C#中,让我以编程方式做到这一点。理想情况下,我就不会去管CMD壳进程
输出。
It would be nice if there exists some class in C# that lets me do this programmatically. Ideally, I wouldn't have to pipe the cmd shell Process
output.
推荐答案
请看到这个问题...
Please see this question...
http://stackoverflow.com/questions/577433/which-pid-listens-on-a-given-port-in-c
基本上你的PInvoke GetExtendedTcpTable()
Basically you PInvoke GetExtendedTcpTable()
这篇关于用netstat -ban(或-oan)的.NET等价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!