我怎样才能得到所有的使用.NET框架活动的TCP连接(没有非托管PE进口!)? [英] How can I get all the the active TCP connections using .NET Framework (no unmanaged PE import!)?

查看:131
本文介绍了我怎样才能得到所有的使用.NET框架活动的TCP连接(没有非托管PE进口!)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能得到所有的使用.NET Framework(没有非托管PE进口!)活动的TCP连接?

How can I get all the the active TCP connections using .NET Framework (no unmanaged PE import!)?

我进入socket编程,并希望进行检查。在我的研究,我发现解决方案,通过导入这我不感兴趣的非托管的DLL文件。

I'm getting into socket programming and would like to check this. In my research I found solutions by importing an unmanaged DLL file which I am not interested in.

推荐答案

我很惊讶有用户告诉我的量,这是不可能做到的纯管理code ...对于未来的用户是谁不知道有关,由它找到工作得很好,我的回答细节:

I'm surprised with the quantity of users telling me that was not possible to do with pure managed code... For future users who is wondering about that, find the details from the answer that worked fine for me:

//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()来列出它,真棒,漂亮。

And call ShowActiveTcpConnections() to list it, awesome and beautiful.

来源: <一个href="http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ipglobalproperties.getactivetcpconnections.aspx">IPGlobalProperties.GetActiveTcpConnections方法 的(MSDN)

Source: IPGlobalProperties.GetActiveTcpConnections Method (MSDN)

这篇关于我怎样才能得到所有的使用.NET框架活动的TCP连接(没有非托管PE进口!)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆