C# - Show Network Traffic (sent and received)

By , 10/27/2007
(1 ratings)
Shows the networktraffic in the console
Translate to VB
/// <summary>
/// Shows the networktraffic.
/// </summary>
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);
    }
}

1 Comments

By Iman, 12/4/2012
Thank you. realy useful and it works.
 

Log in, to comment!