gpt4 book ai didi

C#获取系统网络使用情况

转载 作者:可可西里 更新时间:2023-11-01 08:53:37 24 4
gpt4 key购买 nike

我需要一种方法来获取当前系统网络使用情况的上下变化。

我在网上找到了一些,但它们不适合我。

谢谢你的帮助

代码片段:


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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com