如何以编程方式在 Qt 中获取网络管理器设备名称?

How to get network manager device name in Qt programmatically?(如何以编程方式在 Qt 中获取网络管理器设备名称?)

本文介绍了如何以编程方式在 Qt 中获取网络管理器设备名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有可能在windows中使用Qt/C++获取网络适配器设备名称(网络适配器描述)?

is there any possibility to get the network adapter device name (network adapter description) using Qt / C++ in windows?

我使用了 QNetworkInterface,但它只返回适配器名称.我想知道哪个适配器是 USB 上的以太网.

I used QNetworkInterface, but it return the adapter name only. I want to know which adapter is Ethernet over USB.

QNetworkInterface interface;
QList<QNetworkInterface> IpList = interface.allInterfaces();
for (int i = 0; i < IpList.size(); i++)
    qDebug() << "Interface " << i << ":" << IpList.at(i).humanReadableName();

输出:

推荐答案

是否有可能获得网络适配器设备名称(网络适配器说明)在windows中使用Qt/C++

is there any possibility to get the network adapter device name (network adapter description) using Qt / C++ in windows

答案是否定的.Qt 没有任何功能来获取设备名称(描述).QNetworkInterface 只能获取接口名称和硬件地址(IP).

The answer is no. Qt does not have any functionality to get the device name (description). QNetworkInterface can only obtain the interface name and hardware address (IP).

在 Windows 上,您可以使用这个小代码示例.pAdapter->Description 应该包含您要查找的值.

On Windows you can use this small code example. pAdapter->Description should hold the value you are looking for.

#include <winsock2.h>
#include <iphlpapi.h>
#include <stdio.h>
#include <QCoreApplication>
#pragma comment(lib, "IPHLPAPI.lib")

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    PIP_ADAPTER_INFO pAdapterInfo;
    pAdapterInfo = (IP_ADAPTER_INFO *) malloc(sizeof(IP_ADAPTER_INFO));
    ULONG buflen = sizeof(IP_ADAPTER_INFO);

    if(GetAdaptersInfo(pAdapterInfo, &buflen) == ERROR_BUFFER_OVERFLOW) {
      free(pAdapterInfo);
      pAdapterInfo = (IP_ADAPTER_INFO *) malloc(buflen);
    }

    if(GetAdaptersInfo(pAdapterInfo, &buflen) == NO_ERROR) {
        PIP_ADAPTER_INFO pAdapter = pAdapterInfo;
        while (pAdapter) {
            printf("	Adapter Name: 	%s
", pAdapter->AdapterName);
            printf("	Adapter Desc: 	%s
", pAdapter->Description);
            printf("

");
            pAdapter = pAdapter->Next;
      }
    }
    return a.exec();
}

示例输出

    Adapter Name:   {DF6051AF-8F8F-4AA8-94A9-34656236F101}
    Adapter Desc:   VMware Virtual Ethernet Adapter for VMnet1


    Adapter Name:   {13C8DF49-6D60-4702-9B3A-688B2E372E42}
    Adapter Desc:   TAP-Windows Adapter V9


    Adapter Name:   {42635D10-33A3-4FE9-96BA-1071808B6E2B}
    Adapter Desc:   Realtek PCIe GBE Family Controller


    Adapter Name:   {AA62E2BA-D140-4C2C-A1B5-58082ED21E00}
    Adapter Desc:   1 x 1 11b/g/n Wireless LAN PCI Express Half Mini Card-Ad apter


    Adapter Name:   {7AE540D3-69FE-4BEE-A5CA-482CAF06DAB8}
    Adapter Desc:   VMware Virtual Ethernet Adapter for VMnet8

这篇关于如何以编程方式在 Qt 中获取网络管理器设备名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何以编程方式在 Qt 中获取网络管理器设备名称?

基础教程推荐