C#TCP连接信息统计源码

 

代码如下,平时上课所记录,转载请注明出处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);
            }

        }
    }
}

原文地址:https://www.cnblogs.com/minotmin/p/2699694.html