MinotMin 发表于 2013-1-2 23:02:11

C#TCP连接信息统计源码

<div id="cnblogs_post_body">http://pic002.cnblogs.com/images/2012/447721/2012092410301764.png
代码如下,平时上课所记录,转载请注明出处http://www.cnblogs.com/minotmin/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.NetworkInformation;
namespace test2
{
    public partial class Form1 : Form
    {
      public Form1()
      {
            InitializeComponent();
      }
      
      private void Form1_Load(object sender, EventArgs e)
      {
            IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
            TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();
            foreach (TcpConnectionInformation t in connections)
            {
                listBoxResult.Items.Add("本地端点: " + t.LocalEndPoint.Address);
                listBoxResult.Items.Add("远程端点: " + t.RemoteEndPoint.Address);
                listBoxResult.Items.Add("状态:" + t.State);
            }
      }
    }
}
页: [1]
查看完整版本: C#TCP连接信息统计源码