C#获取系统网络使用情况
发布时间:2020-12-15 06:33:10 所属栏目:百科 来源:网络整理
导读:我需要一种获取当前系统网络使用情况的方法. 我在网上找到了一些,但是并没有为我工作. 谢谢你的帮助 代码段: private void timerPerf_Tick(object sender,EventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) return; NetworkInterface[] inter
我需要一种获取当前系统网络使用情况的方法.
我在网上找到了一些,但是并没有为我工作. 谢谢你的帮助 代码段: private void timerPerf_Tick(object sender,EventArgs e) { if (!NetworkInterface.GetIsNetworkAvailable()) return; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { this.labelnetup.Text = " Bytes Sent: " + ni.GetIPv4Statistics().BytesSent; this.labelnetdown.Text = " Bytes Rec: " + ni.GetIPv4Statistics().BytesReceived; } } 解决方法
请参阅
Report information from NetworkInterface: network statistics一个很好的示例程序:
using System; using System.Net.NetworkInformation; class MainClass { static void Main() { if (!NetworkInterface.GetIsNetworkAvailable()) return; NetworkInterface[] interfaces = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface ni in interfaces) { Console.WriteLine(" Bytes Sent: {0}",ni.GetIPv4Statistics().BytesSent); Console.WriteLine(" Bytes Received: {0}",ni.GetIPv4Statistics().BytesReceived); } } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |