以太网信息

发布于 2024-10-17 15:40:12 字数 195 浏览 3 评论 0原文

好吧,我在 MSDN 上查看了有关此内容的信息,只发现了这个: GetAdaptersAddresses

我想要获取的是以太网信息,例如描述、发送的字节数、接收的字节数、带宽、延迟等。这可能吗?

Well, i've looked on MSDN about this an only found this: GetAdaptersAddresses

And what i'm trying to get is the Etherned Information, such as Description, Bytes Sent, Bytes Received, Bandwidth, Latency, etc. It's possible?

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

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

发布评论

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

评论(1

吐个泡泡 2024-10-24 15:40:12

您可以通过 GetIfTable2 获得大部分内容GetIfEntry2。如果您需要与 XP 及更早版本兼容,则需要查看 GetIfTableGetIfEntry 代替。 *2 函数提供了更多信息,但仅适用于 Vista 及更高版本。

我不相信两者都会显示延迟——因为你几乎需要做一些测量。同样,带宽只是适配器的额定带宽(例如,100 Mb/s 或1000 Mb/s),而不是与任何特定主机通信时所期望的带宽。

编辑:这是我周围的一些代码,它们应该显示如何使用这些函数的总体思路:

#include <windows.h>
#include <iphlpapi.h>
#include <stdlib.h>
#include <stdio.h>

int main() { 

    MIB_IFTABLE *interfaces;
    unsigned long size = 0;
    int i, j;

    GetIfTable(interfaces, &size, FALSE);

    interfaces = (MIB_IFTABLE *)malloc(size);

    GetIfTable(interfaces, &size, TRUE);

    for (i=0; i<interfaces->dwNumEntries; i++) {
        MIB_IFROW &xf = interfaces->table[i];

        printf("%s\n\t", xf.bDescr);
        for (j=0; j<xf.dwPhysAddrLen; j++) {
            printf("%2.2X", xf.bPhysAddr[j]);
            if ( j!= xf.dwPhysAddrLen-1)
                printf(":");
        }
        printf("\n");
        switch(xf.dwType) {
        case MIB_IF_TYPE_ETHERNET:
            printf("Ethernet");
            break;
        case MIB_IF_TYPE_FDDI:
            printf("FDDI");
            break;
        case MIB_IF_TYPE_TOKENRING:
            printf("Token Ring");
            break;
        case MIB_IF_TYPE_LOOPBACK:
            printf("Loopback adapter");
            break;
        case MIB_IF_TYPE_OTHER:
            printf("Other");
            break;
        }
        printf("\n");
    }
    return 0;
}

You can get most of that with GetIfTable2 and GetIfEntry2. If you need compatibility with XP and earlier, you'll want to look at GetIfTable and GetIfEntry instead. The *2 functions give more information, but only work on Vista and newer.

I don't believe either will show latency though -- for that you pretty much need to do some measuring. Likewise, the bandwidth will be simply the rated bandwidth of the adapter (e.g., 100 Mb/s or 1000 Mb/s), not what you can necessarily expect when communicating with any particular host.

Edit: Here's some code I had lying around that should show the general idea of how to use these functions:

#include <windows.h>
#include <iphlpapi.h>
#include <stdlib.h>
#include <stdio.h>

int main() { 

    MIB_IFTABLE *interfaces;
    unsigned long size = 0;
    int i, j;

    GetIfTable(interfaces, &size, FALSE);

    interfaces = (MIB_IFTABLE *)malloc(size);

    GetIfTable(interfaces, &size, TRUE);

    for (i=0; i<interfaces->dwNumEntries; i++) {
        MIB_IFROW &xf = interfaces->table[i];

        printf("%s\n\t", xf.bDescr);
        for (j=0; j<xf.dwPhysAddrLen; j++) {
            printf("%2.2X", xf.bPhysAddr[j]);
            if ( j!= xf.dwPhysAddrLen-1)
                printf(":");
        }
        printf("\n");
        switch(xf.dwType) {
        case MIB_IF_TYPE_ETHERNET:
            printf("Ethernet");
            break;
        case MIB_IF_TYPE_FDDI:
            printf("FDDI");
            break;
        case MIB_IF_TYPE_TOKENRING:
            printf("Token Ring");
            break;
        case MIB_IF_TYPE_LOOPBACK:
            printf("Loopback adapter");
            break;
        case MIB_IF_TYPE_OTHER:
            printf("Other");
            break;
        }
        printf("\n");
    }
    return 0;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文