每个应用程序中的互联网使用情况

发布于 2024-10-17 11:09:23 字数 72 浏览 1 评论 0原文

我想问我如何获得某些应用程序(如流媒体等)使用的互联网流量。我想用 C# 制作一个程序,但我不知道如何启动它....给一些建议谢谢

i would like to ask how can i get the internet amount that being used by some application like streaming and etc. i would like to make a program using in C# and i don't how can i start it.... give some advice thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿忘初心 2024-10-24 11:09:23

作为起点,我会查看 WinSock API。您可能会找到一种在每个进程的基础上提取流量信息的方法。
如果您想查看总网络使用情况,我会使用性能监控工具。我从 网络搜索< /a>:

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

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);
      }
}
浮生未歇 2024-10-24 11:09:23

据我所知,不存在测量每个应用程序的网络带宽的标准方法。使用标准方法可以获得的最多结果基本上就是 netstatperfmon 显示的内容。计算每个应用程序指标的唯一方法是编写 NDIS 筛选器驱动程序,或使用现有的筛选器驱动程序(例如 WinPcap)。但这两种方法都必须在每台目标计算机上安装驱动程序。

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.

够运 2024-10-24 11:09:23

试试这个:如何在c#中计算网络带宽速度

编辑

现在我更好地理解了这个问题,尝试看看这个其他SO问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文