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

标签 c# networking

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

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

谢谢你的帮助

代码片段:


 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/

相关文章:

c# - XNA/Mono 效果抛出运行时转换异常

c# - Action<T> vs 匿名方法问题

c# - 许多神奇的数字

c++ - 两个应用程序如何监听一个端口?

wcf - 在 .net/WCF 中检测连接速度/带宽

android - 即使在 Android N 上,如何获取应用程序(或全部)的当前网络使用情况?

networking - 是什么让 SFTP 和 SCP 协议(protocol)的吞吐量不同

c# - 无法通过C#使用EmguCV打开mpg文件进行捕获

linux - 如何获取 Linux/UNIX 上当前的网络接口(interface)吞吐量统计信息?

c# - 测试 Convert.ChangeType 是否可以在两种类型之间工作