本文介绍了监控进程的网络使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C# 或 C/C++ 中有没有办法 &Win32 监视某个进程的网络使用情况(显然该应用程序不是由您构建的)?我只想监控一个进程大约一个小时,然后返回仅由该进程使用的字节,例如limewire.

有可能吗?我知道 windows 上的 netstat -e 会告诉您发送/接收的总字节数,但这是针对所有进程的.

如果我不能只返回一个进程的使用情况,我怎样才能得到整个系统发送/接收的字节数?作为 netstat 显示,除了我只想要整数.

例如:

网络状态 -e收到 发送字节 2111568926 1133174989单播报文 3016480 2711006非单播数据包 3122 1100丢弃 0 0错误 0 0未知协议 0

我只想得到 2 个变量,比如 rec = 2111568926 和 sent = 1133174989

解决方案

[ 2021 由于网络监视器在 Windows XP 之后停止使用,链接已失效.]

这是可能的,但如果我没记错的话,您必须创建一个网络驱动程序来过滤所有网络流量,然后找出哪个进程创建了流量.

Microsoft 有一个免费的应用程序,名为 Microsoft 网络监视器 3.2(下载).根据发行说明,它还有一个 api 可以使用.

网络监视器 API:创建您自己的捕获、解析和分析网络流量!

这里是一篇关于这些 API 的博客文章.

在我看来,您应该使用此 API(或其他 API,例如 WinPcap)来过滤流量,而不是编写您自己的设备驱动程序.

Is there a way in C# or C/C++ & Win32 to monitor a certain process's network usage (Without that application being built by you obviously)? I would like to monitor just 1 process for like an hour or so, then return the bytes used by only that process, such as limewire for example.

Is it possible? I know netstat -e on windows will tell you total bytes sent/received, but that is for all processes.

edit: If i can't return just one processes usage, how can i get the bytes sent/received by the entire system? as netstat displays except i just want the integers.

eg:

netstat -e

                           Received            Sent

Bytes                    2111568926      1133174989
Unicast packets             3016480         2711006
Non-unicast packets            3122            1100
Discards                          0               0
Errors                            0               0
Unknown protocols                 0

I just want to get 2 variables, like rec = 2111568926 and sent = 1133174989

解决方案

[ 2021 edit: links are dead as the Network Monitor is discontinued after Windows XP. ]

It's possible, but if I'm not mistaken you'll have to create a network driver to filter all network traffic and than figure out which process created the traffic.

Microsoft has an free application for it called Microsoft Network Monitor 3.2 (download). According to the release notes it also has an api to use.

Here is a blog post about these API's.

In my opinion you should use this API (or another API such as WinPcap) to filter the traffic instead of writing your own device driver.

这篇关于监控进程的网络使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 05:54