How can I access netstat-like Ethernet statistics

2019-01-15 10:22发布

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

7条回答
爷的心禁止访问
2楼-- · 2019-01-15 11:17

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

查看更多
登录 后发表回答