C# IPGlobalStatistics获取本机网络流量信息
完整代码:
引入命名空间:
using System.Net.NetworkInformation;
完整代码:
namespace IPGlobalStatics
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties();
IPGlobalStatistics ipstat = properties.GetIPv4GlobalStatistics();
lst_NetworkInfo.Items.Add("本机所在域:" + properties.DomainName);
lst_NetworkInfo.Items.Add("接收数据包:" + ipstat.ReceivedPackets);
lst_NetworkInfo.Items.Add("转发数据包:" + ipstat.ReceivedPacketsForwarded);
lst_NetworkInfo.Items.Add("传送数据包:" + ipstat.ReceivedPacketsDelivered);
lst_NetworkInfo.Items.Add("丢弃数据包:" + ipstat.ReceivedPacketsDiscarded);
}
}
}