是否有托管类/方法可以提供特定Windows进程使用的TCP端口号?如何确定Windows进程在C#中使用的tcp端口
我真的很以下CMD线的.NET相当于:
netstat -ano |find /i "listening"
是否有托管类/方法可以提供特定Windows进程使用的TCP端口号?如何确定Windows进程在C#中使用的tcp端口
我真的很以下CMD线的.NET相当于:
netstat -ano |find /i "listening"
除PID,看看这个:
IPGlobalProperties ipProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] endPoints = ipProperties.GetActiveTcpListeners();
TcpConnectionInformation[] tcpConnections =
ipProperties.GetActiveTcpConnections();
foreach (TcpConnectionInformation info in tcpConnections)
{
Console.WriteLine("Local: {0}:{1}\nRemote: {2}:{3}\nState: {4}\n",
info.LocalEndPoint.Address, info.LocalEndPoint.Port,
info.RemoteEndPoint.Address, info.RemoteEndPoint.Port,
info.State.ToString());
}
Console.ReadLine();
来源:Netstat in C#更
有点研究带来这样的:Build your own netstat.exe with c#。这使用P/Invoke调用GetExtendedTcpTable
并使用与netstat
相同的结构。
在这里看到的netstat的等效于C#:http://towardsnext.wordpess.com/2009/02/09/netstat-in-c/
更新:链接断开,但这里有一个等价的:http://www.timvw.be/2007/09/09/build-your-own-netstatexe-with-c
没有找到页面:( – Misaz 2016-01-25 09:20:29
并获得PID? – Revious 2015-03-06 11:44:37