Question

Good evening,

does anyone know a native/elegant way to read out the available network interfaces and their current througput (e.g. bytes/sec) in .net?

Cheers & thanks, -Jörg

Was it helpful?

Solution

You can get that information from WMI ...

// Reference System.Management
var mos = new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapter");
var nics = mos.Get();

foreach (var n in nics)
{
  Console.WriteLine("{0} {1}", n["Name"], n["Speed"]);
}

List of properties on Win32_NetworkAdapter.

If you want real-time data (which I think you might be asking for), use PerformanceCounter instead. These correspond to perfmon counters. For example ...

var counter = new PerformanceCounter("Network Interface", "Bytes Total/sec", 
                                      /* your net interface name here */);
Console.WriteLine(counter.RawValue);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top