此代码工作正常,但我想知道是否可以获取有关谁发起每个连接的信息?就像在哪个端点发起连接一样。这可能吗?
using System.Net.NetworkInformation;
public static void ShowActiveTcpConnections()
{
Console.WriteLine("Active TCP Connections");
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
foreach (TcpConnectionInformation c in connections)
{
Console.WriteLine("{0} <==> {1}",
c.LocalEndPoint.ToString(),
c.RemoteEndPoint.ToString());
}
}
答案 0 :(得分:0)
在列表端口上收到TCP连接。入站连接将从GetActiveTcpListeners()返回,并可从GetActiveTcpConnections()中扣除,以获得出站连接。
您可以查看http://www.timvw.be/2007/09/09/build-your-own-netstatexe-with-c/
这将告诉您如何获得该过程:
Console.WriteLine(&#34; {0}&#34;,processModule.FileName);