QT += network
.cpp source file
#include#include QString _MAC = ""; QString _IP = ""; QTcpSocket socket; socket.connectToHost("8.8.8.8", 53); // google DNS, or something else reliable if (socket.waitForConnected(3000)) { // qInfo() << socket.localAddress().toString(); foreach(QNetworkInterface interface, QNetworkInterface::allInterfaces()){ foreach (QNetworkAddressEntry entry, interface.addressEntries()){ if(socket.localAddress().toString() == entry.ip().toString()){ qInfo() << socket.localAddress().toString() << " - " << interface.hardwareAddress(); _MAC = interface.hardwareAddress(); _IP = socket.localAddress().toString(); } } } } else { qInfo() << socket.errorString(); } socket.destroyed();
댓글 없음 :
댓글 쓰기