如何从 Windows 程序访问类似 netstat 的以太网统计信息
如何从 C/C++ 代码(例如 netstat -e)访问以太网统计信息?
Interface Statistics
Received Sent
Bytes 21010071 15425579
Unicast packets 95512 94166
Non-unicast packets 12510 7
Discards 0 0
Errors 0 3
Unknown protocols 0
How can I access Ethernet statistics from C/C++ code like netstat -e?
Interface Statistics
Received Sent
Bytes 21010071 15425579
Unicast packets 95512 94166
Non-unicast packets 12510 7
Discards 0 0
Errors 0 3
Unknown protocols 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
WMI 将提供这些读数:
这些类在 Windows XP 或更高版本上可用。 您可能必须放弃 Windows 2000 上匹配的“Win32_PerfRawData”类,并在显示输出之前进行更多的数学运算。
在 MSDN 中查找有关所有这些内容的文档。
The WMI will provide those readings:
These classes are available on Windows XP or newer. You may have to resign to the matching "Win32_PerfRawData" classes on Windows 2000, and do a little bit more of math before you can display the output.
Find documentation on all of them in the MSDN.
网络统计数据的一个不错的起点是 GetIpStatistics< /a> 调用 Windows IPHeper 函数。
还有其他几种可能更便携的方法:-
A good place to start for network statistics would be the GetIpStatistics call in the Windows IPHelper functions.
There are a couple of other approaches that are possibly more portable:-
让我自己回答一下,就像我在另一个论坛上问过同样的问题一样。
WMI 很好,但使用 IpHlpApi 更容易:
Let me answer to myself, as I asked the same on another forum.
WMI is good, but it's easier to use IpHlpApi instead:
Szia,
来自 http://en.wikipedia.org/wiki/Netstat
CodeProject 中的 MFC 示例: http://www.codeproject.com/KB/applications/wnetstat .aspx
Szia,
from http://en.wikipedia.org/wiki/Netstat
MFC sample at CodeProject: http://www.codeproject.com/KB/applications/wnetstat.aspx
您可能会找到一个可行的 WMI 性能计数器,例如Win32_PerfRawData_Tcpip_NetworkInterface。
You might find a feasable WMI performance counter, e.g. Win32_PerfRawData_Tcpip_NetworkInterface.
参见Google Groups,原始netstats源代码已发布多次(win32 api)
See Google Groups, original netstats source code has been posted many times (win32 api)
正如上面的答案所示,WMI 性能计数器包含一些数据。 请注意,在更高版本的 Windows 中,性能计数器在 v4 和 v6 中进行了细分,因此查询为:
SELECT * FROM Win32_PerfFormattedData_Tcpip_IPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_TCPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_UDPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_ICMP
选择
SELECT * FROM Win32_ PerfFormattedData_Tcpip_IPv6 选择 * 从 Win32_PerfFormattedData_Tcpip_TCPv6
*从 Win32_PerfFormattedData_Tcpip_UDPv6
选择 * 从 Win32_PerfFormattedData_Tcpip_ICMPv6
As above answers suggest, WMI performance counters contains some data. Just be aware that in later versions of windows the perf counters are broken down in v4 vs v6 so the queries are:
SELECT * FROM Win32_PerfFormattedData_Tcpip_IPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_TCPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_UDPv4
SELECT * FROM Win32_PerfFormattedData_Tcpip_ICMP
SELECT * FROM Win32_PerfFormattedData_Tcpip_IPv6
SELECT * FROM Win32_PerfFormattedData_Tcpip_TCPv6
SELECT * FROM Win32_PerfFormattedData_Tcpip_UDPv6
SELECT * FROM Win32_PerfFormattedData_Tcpip_ICMPv6