Function to find the network traffic

using System.Diagnostics
private static void ShowNetworkTraffic()
{
PerformanceCounterCategory performanceCounterCategory =
new PerformanceCounterCategory("Network Interface");

// 1st NIC !
string instance = performanceCounterCategory.GetInstanceNames()[0];

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);
}
}


Comments

Author: vijetha22 May 2008 Member Level: Gold   Points : 2

Add the Namespace System.Diagnostics

Author: Kapil Dhawan17 Jun 2008 Member Level: Gold   Points : 2

Hello
Nice piece of code
Thanks for sharing your knowledge with us.
I hope to see more good code from your side
This code is going to help lots of guys.
Ton Thanks to you
Regards,
Kapil

Guest Author: Atena Megano11 Apr 2012

how could i detect which packets are for LAN and which are for Internet ?



  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: