0

hi guys i have a some problem about getting value received and sent in local area connection

I want get this value

enter image description here

i have code like this

public static void DisplayDnsConfiguration()
    {
        NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
        foreach (NetworkInterface adapter in adapters)
        {
            IPInterfaceProperties properties = adapter.GetIPProperties();
            Console.WriteLine(adapter.Description);
            Console.WriteLine("  DNS suffix .............................. : {0}",
                properties.DnsSuffix);
            Console.WriteLine("  DNS enabled ............................. : {0}",
                properties.IsDnsEnabled);
            Console.WriteLine("  Dynamically configured DNS .............. : {0}",
                properties.IsDynamicDnsEnabled);
        }
        Console.WriteLine();
    }

and my question is, how can i get that value using this code, because many people sugest me to use NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

please help me i don't know what i have to do next

and sory for my bad english

Mike Mat
  • 632
  • 7
  • 15

1 Answers1

0

You can use performance counters as stated in this stackoverflow answer.

Code:

private static void ShowNetworkTraffic() {
  PerformanceCounterCategory performanceCounterCategory = new PerformanceCounterCategory("Network Interface");
  string instance = performanceCounterCategory.GetInstanceNames()[0]; // 1st NIC !
  PerformanceCounter performanceCounterSent = new PerformanceCounter("Network Interface", "Bytes Sent/sec", instance);
  PerformanceCounter performanceCounterReceived = new PerformanceCounter("Network Interface", "Bytes Received/sec", instance);

  for (int i = 0; i < 10; i++) {
    Console.WriteLine("bytes sent: {0}k\tbytes received: {1}k", performanceCounterSent.NextValue() / 1024, performanceCounterReceived.NextValue() / 1024);
    Thread.Sleep(500);
  }
}
Moerwald
  • 10,448
  • 9
  • 43
  • 83
  • `performanceCounterSent.NextValue()` holds the value of sent bytes, `performanceCounterReceived.NextValue()` holds the value of received bytes. – Moerwald Nov 13 '17 at 07:19
  • sorry i have not understood too much, can you give me another example to get the overall value of bytes sent when pc start live up to now, i have been stuck on this problem so i am very grateful for your help – Sutrasno Andre Wibowo Nov 15 '17 at 03:01