How to get network manager device name in Qt programmatically?(如何以编程方式在 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 中获取网络管理器设备名称?
基础教程推荐
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 初始化列表*参数*评估顺序 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
