开发者

internet usage in every application

开发者 https://www.devze.com 2023-02-10 04:18 出处:网络
i would like to ask how can i get the internet amount that being used by some application like streaming and etc. i would lik开发者_运维百科e to make a program using in C# and i don\'t how can i start

i would like to ask how can i get the internet amount that being used by some application like streaming and etc. i would lik开发者_运维百科e to make a program using in C# and i don't how can i start it.... give some advice thanks


As a starting point I'd look at the WinSock API. You may find a way of pulling traffic information on a per process basis. If you want to see total network usage, I'd use the Performance Monitoring tools. I found this example from a web search:

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


To the best of my knowledge, there exists no standard method to measure network bandwidth per-application. The most you can get with standard means is essentially what netstat and perfmon show. The only way to calculate per-application metrics is to write an NDIS filter driver, or use an existing filter driver such as WinPcap. But both ways you'll have to install a driver on every target machine.


Try this: How to calculate network bandwidth speed in c#

EDIT

Now that I understand the question better try looking at this other SO question

0

精彩评论

暂无评论...
验证码 换一张
取 消