Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Uniquely identify a machine
Forum Updated to NodeBB v4.3 + New Features

Uniquely identify a machine

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 814 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by
    #1

    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 of QNetworkInterface::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.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      H 1 Reply Last reply
      0
      • mrjjM mrjj

        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.

        H Offline
        H Offline
        hbatalha
        wrote on last edited by
        #3

        @mrjj thanks for the quick reply

        I dont think its persistent across reinstall or another os at all.

        So my best bet is to use the mac address of a network interface?

        mrjjM 1 Reply Last reply
        0
        • H hbatalha

          @mrjj thanks for the quick reply

          I dont think its persistent across reinstall or another os at all.

          So my best bet is to use the mac address of a network interface?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @hbatalha

          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.

          H 1 Reply Last reply
          0
          • mrjjM mrjj

            @hbatalha

            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.

            H Offline
            H Offline
            hbatalha
            wrote on last edited by hbatalha
            #5

            @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.

            mrjjM 1 Reply Last reply
            0
            • H hbatalha

              @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.

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              H 1 Reply Last reply
              0
              • mrjjM mrjj

                @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.

                H Offline
                H Offline
                hbatalha
                wrote on last edited by
                #7

                @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.

                mrjjM 1 Reply Last reply
                0
                • H hbatalha

                  @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.

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @hbatalha
                  Hi
                  Yes composite keys suffer from this as seen with Windows activation.
                  But if the goal is to solely count users, then it should be rare that someone change the mac ID
                  as to cheat with that.

                  H 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    @hbatalha
                    Hi
                    Yes composite keys suffer from this as seen with Windows activation.
                    But if the goal is to solely count users, then it should be rare that someone change the mac ID
                    as to cheat with that.

                    H Offline
                    H Offline
                    hbatalha
                    wrote on last edited by
                    #9

                    @mrjj said in Uniquely identify a machine:

                    then it should be rare that someone change the mac ID

                    yeah that's what I counting on.

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved