2009-11-30 46 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

相關問題