首页 > 其他 > 详细

C#检测网卡和网络统计信息

时间:2014-03-14 18:25:03      阅读:275      评论:0      收藏:0      [点我收藏+]

 

bubuko.com,布布扣
using System;
using System.Collections.Generic;
using System.Net.NetworkInformation;

public class MyClass
{
    public static void Main()
    {
        //Host Info
        IPGlobalProperties  ipProp = IPGlobalProperties.GetIPGlobalProperties();
        string hostInfo = 
            string.Format("Host Name:{0}\nDomain Name:{1}\n\n",ipProp.HostName,ipProp.DomainName);
        //statistics
        IPGlobalStatistics ipStat = ipProp.GetIPv4GlobalStatistics();
        TcpConnectionInformation[] tcpConns = ipProp.GetActiveTcpConnections();
        string stat="";
        foreach(TcpConnectionInformation info in tcpConns)
            stat += string.Format("localhost:{0}\t{1}:{2}\tstate:{3}", info.LocalEndPoint.Port,
            info.RemoteEndPoint.Address,info.RemoteEndPoint.Port, info.State);
        //Network Interface
        string niInfo="";
        NetworkInterface[] nis = NetworkInterface.GetAllNetworkInterfaces();
        foreach(NetworkInterface ni in nis)
            niInfo += string.Format("\n\nName:{0}\nStatus:{1}\nSpeed:{2}\nMAC:{3}", 
            ni.Name,ni.OperationalStatus,ni.Speed,ni.GetPhysicalAddress());

        System.Windows.Forms.MessageBox.Show(hostInfo + niInfo);        
        System.Windows.Forms.MessageBox.Show(stat);        
        Console.ReadKey();
    }
}
bubuko.com,布布扣

C#检测网卡和网络统计信息,布布扣,bubuko.com

C#检测网卡和网络统计信息

原文:http://www.cnblogs.com/flaaash/p/3599304.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!