Uniquely identify a machine
-
I want to be able to uniquely the computer my app is running on, meaning that if a user uses my app using the same computer in Windows and Linux I should get the same id.
Right now I am using the mac address ofQNetworkInterface::Wifi
but as this can easily spoofed ,I am looking for a more reliable way.I came across QSysInfo::machineUniqueId() and it seems to be the way but I am not sure how persistent it is. If it remain the same across OS reinstalls and different OS'es installed in the machine.
-
Hi
I dont think its persistent across reinstall or another os at all.For licenses purpose, often a composite key is generated with mac ID, hard drive id and
other factors to be able to spot if its its another PC. -
Hi
well depending on what the goal is, yes that should be good.
You could mix it with#include <qt_windows.h> QString tdrive = "C:\\"; DWORD dwSerialNumber = 0; bool ret = GetVolumeInformation((WCHAR *)tdrive.utf16(),NULL,NULL,&dwSerialNumber,NULL,NULL,NULL,NULL); if (ret) { qDebug()<<"dwSerialNumber " << dwSerialNumber; }
for Windows.
as to make it harder to run your app in a virtual machine where it's super easy to set mac ID to anything.
make sure not to keep the macID you compare to as clear text.
-
@mrjj Thanks for the code.
I guess I will just get the mac address and run it under the risk of it being spoofed.well depending on what the goal is, yes that should be good.
My goal is to able to tell how many people are using my app.
make sure not to keep the macID you compare to as clear text.
I am not sure I know what you mean, could you elaborate more?
Edit: this is the function I am using to get mac address:
QString Util::getMacAddress() { for(const QNetworkInterface& iface: QNetworkInterface::allInterfaces()) { if (iface.type() == QNetworkInterface::Wifi) { return iface.hardwareAddress(); } } foreach(QNetworkInterface netInterface, QNetworkInterface::allInterfaces()) { // Return only the first non-loopback MAC Address if (!(netInterface.flags() & QNetworkInterface::IsLoopBack)) { QString macAddress = netInterface.hardwareAddress(); if(! macAddress.isEmpty()) return macAddress; } } return QString(); }
Edit 2: I could make a combination of a set of system info I can get, like gpu, ram, cpu etc, see this article.
-
@hbatalha said in Uniquely identify a machine:
My goal is to able to tell how many people are using my app.
ah. forget about storing as clear text. i thought you would use it to validate. :)
Yes making a composite key from other hardware components etc will help to determine if its a new user or he just reinstalled.
-
@mrjj said in Uniquely identify a machine:
Yes making a composite key from other hardware components etc will help to determine if its a new user or he just reinstalled.
I found it practically impossible to get a unique id, even when adding other hardware components info because the base will always be the mac address, and if it is spoofed it will change the generated id.
I don't know if it is a real need but manufacturer could very well provide a unique id for each device.Thanks for your answers, they were really helpful.