Qt 获取本机网卡的IP与MAC信息
在Qt中,我们可以使用以下代码来获取本机网卡的IP地址和MAC地址:
#include <QtNetwork>
#include <QDebug>
#include <QList>
#include <QNetworkInterface>
int main()
{
int i = 0;
QList<QNetworkInterface> ifaces = QNetworkInterface::allInterfaces();
foreach (QNetworkInterface iface, ifaces)
{
++i;
if(iface.hardwareAddress() != NULL)
{
qDebug() << "Name:" << iface.name() << ", DisplayName:" << iface.humanReadableName();
qDebug() << "Address:" << iface.addressEntries().first().ip().toString() << ", HardwareAddress:" << iface.hardwareAddress();
cb->addItem(iface.humanReadableName());
}
}
if(i == 0)
{
qDebug("No interfaces found! Make sure WinPcap is installed.");
}
return 0;
}