diff --git a/src/core/utilities.cpp b/src/core/utilities.cpp index d7ba50d43..cf6ffee49 100644 --- a/src/core/utilities.cpp +++ b/src/core/utilities.cpp @@ -59,6 +59,7 @@ #include #include #include +#include #include #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)