I need a way to get the current system network usage, up and down.
I found some on the net but they're not working out for me.
Thanks for your help
Code snippet:
 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;
            }
        }
                You can get the current system's network usage by working with PerformanceCounterCategory too:
using System;
using System.Diagnostics;
class Program
{
    static void Main()
    {
        PerformanceCounterCategory pcg = new PerformanceCounterCategory("Network Interface");
        string instance = pcg.GetInstanceNames()[0];
        PerformanceCounter pcsent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance);
        PerformanceCounter pcreceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);
        Console.WriteLine("Bytes Sent: {0}", pcsent.NextValue() / 1024);
        Console.WriteLine("Bytes Received: {0}", pcreceived.NextValue() / 1024);
    }
}
Source: http://dotnet-snippets.com/snippet/show-network-traffic-sent-and-received/580
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With