Add function to get mac address
This commit is contained in:
parent
a1745289be
commit
c146290e07
|
@ -59,6 +59,7 @@
|
|||
#include <QSettings>
|
||||
#include <QtEvents>
|
||||
#include <QMessageBox>
|
||||
#include <QNetworkInterface>
|
||||
#include <QtDebug>
|
||||
|
||||
#ifdef Q_OS_LINUX
|
||||
|
@ -815,6 +816,28 @@ QString UnicodeToAscii(const QString &unicode) {
|
|||
|
||||
}
|
||||
|
||||
QString MacAddress() {
|
||||
|
||||
QString ret;
|
||||
|
||||
for (QNetworkInterface &interface : QNetworkInterface::allInterfaces()) {
|
||||
if (
|
||||
(interface.hardwareAddress() == "00:00:00:00:00:00") ||
|
||||
(interface.flags() & QNetworkInterface::IsLoopBack) ||
|
||||
!(interface.flags() & QNetworkInterface::IsUp) ||
|
||||
!(interface.flags() & QNetworkInterface::IsRunning)
|
||||
) { continue; }
|
||||
if (ret.isEmpty() || interface.type() == QNetworkInterface::Ethernet || interface.type() == QNetworkInterface::Wifi) {
|
||||
ret = interface.hardwareAddress();
|
||||
}
|
||||
}
|
||||
|
||||
if (ret.isEmpty()) ret = "00:00:00:00:00:00";
|
||||
|
||||
return ret;
|
||||
|
||||
}
|
||||
|
||||
} // namespace Utilities
|
||||
|
||||
ScopedWCharArray::ScopedWCharArray(const QString &str)
|
||||
|
|
Loading…
Reference in New Issue