2009-11-30 75 views

回答

15

除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相同的结构。

+1

并获得PID? – Revious 2015-03-06 11:44:37

相关问题