gpt4 book ai didi

c# - 如何使用 .NET Framework 获取所有事件的 TCP 连接(无非托管 PE 导入!)?

转载 作者:可可西里 更新时间:2023-11-01 08:04:08 25 4
gpt4 key购买 nike

如何使用 .NET Framework 获取所有事件的 TCP 连接(没有非托管 PE 导入!)?

我正在学习套接字编程,想检查一下。在我的研究中,我通过导入一个我不感兴趣的非托管 DLL 文件找到了解决方案。

最佳答案

令我感到惊讶的是,有大量用户告诉我,使用纯托管代码是不可能的...对于 future 对此感到疑惑的用户,请从对我来说很好的答案中找到详细信息:

//Don't forget this:
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());
}
}

然后调用ShowActiveTcpConnections()列出来,真棒又漂亮。

来源: IPGlobalProperties.GetActiveTcpConnections Method (MSDN)

关于c# - 如何使用 .NET Framework 获取所有事件的 TCP 连接(无非托管 PE 导入!)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13806435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com