是否有託管類/方法可以提供特定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