Ngoại trừ PID, hãy xem:
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();
Nguồn: Netstat in C# nghiên cứu thêm
Một chút đem này: Build your own netstat.exe with c#. Điều này sử dụng P/Gọi để gọi GetExtendedTcpTable
và sử dụng cấu trúc giống như netstat
.
Nguồn
2009-11-30 12:04:07
Và để nhận được PID? – Revious