C#实现TCP连接信息统计的方法

2019-12-26 12:28:37刘景俊

易采站长站为您分析C#实现TCP连接信息统计的方法,可实现有效获取TCP连接信息及连接状态的功能,需要的朋友可以参考下

本文实例讲述了C#实现TCP连接信息统计的方法。。具体实现方法如下:

 

 
  1. using System;  using System.Collections.Generic; 
  2. using System.ComponentModel;  using System.Data; 
  3. using System.Drawing;  using System.Linq; 
  4. using System.Text;  using System.Windows.Forms; 
  5. using System.Net.NetworkInformation;  namespace test2 
  6. {  public partial class Form1 : Form 
  7. {  public Form1() 
  8. {  InitializeComponent(); 
  9. }  private void Form1_Load(object sender, EventArgs e) 
  10. {  IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); 
  11. TcpConnectionInformation[] connections = properties.GetActiveTcpConnections();  foreach (TcpConnectionInformation t in connections) 
  12. {  listBoxResult.Items.Add("本地端点: " + t.LocalEndPoint.Address); 
  13. listBoxResult.Items.Add("远程端点: " + t.RemoteEndPoint.Address);  listBoxResult.Items.Add("状态:" + t.State); 
  14. }  } 
  15. }  } 

希望本文所述对大家的C#程序设计有所帮助。