#include
#include
#include
#include
#include
#ifdef __GNUC__
#include
#elif defined(_MSC_VER)
#if _MSC_VER >= 1400
#include
#endif
#else
#error Only supports MSVC or GCC
#endif
QStringList get_mac();
void getcpuid(unsigned int CPUInfo[4], unsigned int InfoType);
void getcpuidex(unsigned int CPUInfo[4], unsigned int InfoType, unsigned int ECXValue);
QString get_cpuId();
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv)
QString cpu_id = "";
cpu_id = get_cpuId();
qDebug() << cpu_id
QStringList mac_list;
mac_list = get_mac();
for (int i=0; isize(); i++)
{
qDebug() << mac_list.at(i);
}
return a.exec();
}
QStringList get_mac()
{
QStringList mac_list;
QString strMac;
QList ifaces = QNetworkInterface::allInterfaces();
for (int i=0; ii++)
{
QNetworkInterface iface = ifaces.at(i);
if (iface.flags().testFlag(QNetworkInterface::IsUp) && !iface.flags().testFlag(QNetworkInterface::IsLoopBack))
{
if (!(iface.humanReadableName().contains("VMware",Qt::CaseInsensitive)))
{
strMac = iface.hardwareAddress();
mac_list.append(strMac);
}
}
}
return mac_list;
}
QString get_cpuId()
{
QString cpu_id = "";
unsigned int dwBuf[4];
unsigned long long ret;
getcpuid(dwBuf, 1)
ret = dwBuf[3];
ret = ret << 32;
cpu_id = QString::number(dwBuf[3], 16).toUpper();
cpu_id = cpu_id + QString::number(dwBuf[0], 16).toUpper();
return cpu_id;
}
void getcpuid(unsigned int CPUInfo[4], unsigned int InfoType)
{
#if defined(__GNUC__)
__cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]);
#elif defined(_MSC_VER)
#if _MSC_VER >= 1400
__cpuid((int*)(void*)CPUInfo, (int)(InfoType))
#else
getcpuidex(CPUInfo, InfoType, 0)
#endif
#endif
}
void getcpuidex(unsigned int CPUInfo[4], unsigned int InfoType, unsigned int ECXValue)
{
#if defined(_MSC_VER)
#if defined(_WIN64)
__cpuidex((int*)(void*)CPUInfo, (int)InfoType, (int)ECXValue)
#else
if (NULL==CPUInfo) return;
_asm{
// load. 读取参数到寄存器.
mov edi, CPUInfo;
mov eax, InfoType;
mov ecx, ECXValue;
cpuid;
mov [edi], eax;
mov [edi+4], ebx;
mov [edi+8], ecx;
mov [edi+12], edx;
}
#endif
#endif
}