how to generate a unique integer specific to a computer

Last post 12-04-2009 8:20 AM by Aquaren. 8 replies.

Sort Posts:

  • how to generate a unique integer specific to a computer

    22 hours, 38 minutes ago
    • Member
      57 point Member
    • pauldavidson
    • Member since 09-24-2006, 12:01 PM
    • Scotland
    • Posts 166

    Hey all.

    I am writing software, that will only be allowed to be run on a single machine. What ways are good for generating a unique integer that I can check against to make sure the machine that is requesting something from my server, is the machine that it was first installed on.

    I don't want to use a single number that is easy to figure out where it has come from. So a combination of pieces of hardware, and somehow disguise the number to include these or something.

    Any ideas?

    Filed under:
  • Re: how to generate a unique integer specific to a computer

    21 hours, 33 minutes ago
    • Member
      204 point Member
    • Aquaren
    • Member since 11-21-2009, 12:37 PM
    • Posts 48

    what about using the IP and/or MAC address?

  • Re: how to generate a unique integer specific to a computer

    21 hours, 31 minutes ago
    • Member
      57 point Member
    • pauldavidson
    • Member since 09-24-2006, 12:01 PM
    • Scotland
    • Posts 166

    2 things I was thinking about, was the mac address and hard drive serials...but I've read somewhere that the mac address may not be unique for clustered servers where they share the mac address. And I downloaded code to get the hard drive serials, but it holds some weird results for serials!

  • Re: how to generate a unique integer specific to a computer

    21 hours, 25 minutes ago
    • Member
      204 point Member
    • Aquaren
    • Member since 11-21-2009, 12:37 PM
    • Posts 48

    What is the specific business problem you are trying to solve? What is the problem with more that one machine running the software? Are you running AD? If so, push out a GPO that prevents the software from being installed.

  • Re: how to generate a unique integer specific to a computer

    21 hours, 11 minutes ago
    • Member
      57 point Member
    • pauldavidson
    • Member since 09-24-2006, 12:01 PM
    • Scotland
    • Posts 166

    AD? GPO? sorry I have no idea what you mean :)

    Basically I am writing retail software, and for every request that a clients machine makes to my server, my server will need to validate the request. They will have a licence ID, which I can validate that they are allowed to send the request, but I am also going to use some sort of hardware token that they pass along with the request, so that I can validate that the computer that is requesting something, is the correct one. 

    I will also need to create some sort of activation serial as well, that their machine creates when it is sending a request to activate the licence, and I was going to use something to do with the hardware token, so that I can also recreate this activation serial.

    But they may also require to do it over the phone, hence why it needs to be readable, we are planning on using integers for it.


  • Re: how to generate a unique integer specific to a computer

    20 hours, 55 minutes ago
    • Member
      204 point Member
    • Aquaren
    • Member since 11-21-2009, 12:37 PM
    • Posts 48

    If it is something they need to do over the phone, you are probably better of just generating the number internally and supplying it to the user with the license ID.

  • Re: how to generate a unique integer specific to a computer

    4 hours, 32 minutes ago
    • Member
      57 point Member
    • pauldavidson
    • Member since 09-24-2006, 12:01 PM
    • Scotland
    • Posts 166

    it would need to be a number that both sides could recreate, for authentication purposes as well. 99% of the time, it will be done through WCF services, but that 1% needs to be catered for as well

  • Re: how to generate a unique integer specific to a computer

    1 hour, 38 minutes ago
    • Member
      57 point Member
    • pauldavidson
    • Member since 09-24-2006, 12:01 PM
    • Scotland
    • Posts 166

    I've managed to get code working that will get me the mac address the motherboard serial. So I think I am going to work with these rather than include things like the hard disk serials. Is there any good way to convert these into an Int32? Other than, say, only taking the numbers from motherboard serial and mac address and joining them in some way?

  • Re: how to generate a unique integer specific to a computer

    37 minutes ago
    • Member
      204 point Member
    • Aquaren
    • Member since 11-21-2009, 12:37 PM
    • Posts 48

    I am assuming that the macAddress will be in the format 00-00-00-00-00. This function will return a concatenated string of the mac address hex values converted to integers. This will not return a valid integer (unless you want to convert it), because the first number of the mac address could be 0.

            public string ConvertMACAddressToNumber(string macAddress)
            {
                string[] macAddressArray = macAddress.Split('-');
                StringBuilder retVal = new StringBuilder();
    
                foreach (string item in macAddressArray)
                {
                    int hex = (int)System.Convert.ToUInt32("0x" + item, 16);
                    retVal.Append(hex.ToString());
                }
    
                return retVal.ToString();
            } 
Page 1 of 1 (9 items)