我需要一种方法来获取当前系统网络使用情况的上下变化。
我在网上找到了一些,但它们不适合我。
谢谢你的帮助
代码片段:
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);
}
}
}
关于C#获取系统网络使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2081827/