Generating Unique Machine IDs

A very helpful feature that Serial Sense offers is its ability to automatically manage what machines an end user can activate and use your products. This is valuable for any developer that sells software on a per-machine basis. For example, company ABC Plugins wants to sell its software as a single-machine license for $49 and a 5-machine package license for $149. The 5-machine license may a better option for a customer running a business for all employee use, while the single-machine license is clearly the better choice for personal use.

As you can see, having a function that uniquely identifies the machine executing that software is a very common need. Fortunately, there are quite a few ways of achieving this. Here I’ll detail how to accomplish generating a unique machine ID on Windows, Linux, and Mac OS X.

Mac OS X

Like most developer functions on the Mac, getting a unique machine ID is bare-bones simple. All you have to do is run the system_profiler shell command. To grab only the unique machine ID from within your program or script, call this shell command:

$ system_profiler | grep -i "Serial Number (system):" | awk '{print $4}'

This snippet’s output will return the Macintosh computer’s serial number, which is unique to every mac. I won’t go into detail on how to get this data into your program as every language has different facilities for running shell scripts. If your software will run on a hackintosh computer, where Mac OS X is installed on a non-Apple computer, then this snippet won’t be so reliable. In that case, take a look at the second half of the linux section in this article for an alternative.


Windows will require a bit of registry magic for generating a unique machine ID. Interestingly enough, Windows XP was the first operating system to assign a unique machine uuid on install. In the Windows registry, you can find the key “MachineGuid” in: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Cryptography

Again, I won’t give examples on how to get registry values as this is going to differ from language to language; however, finding the uuid in the registry is a good option.


Linux is a bit trickier since it doesn’t have a machine ID set anywhere. I like to generate unique machine IDs under Linux based on ethernet mac addresses, where I will combine them all into a string without any colons. Use the below shell command:

$ ifconfig | grep -i hwaddr | awk '{print $1$5}' | sed 's/://g' | xargs echo | sed 's/ //g'

This snippet runs ifconfig, grep’s out the “hwaddr” lines that we are interested in, uses awk to grab the interface name, and finally the mac address of that interface. We then remove the colons and line breaks–if there are multiple interfaces using xargs and echo. Finally, we remove the spaces to smush everything together into one long string: the machine’s unique ID!

You can also use this method on Mac OS X if you don’t want to use the serial. This is effective in cases where someone is running Mac OS X on a non-Apple computer, which doesn’t have a machine serial. For Mac OS X, you will need to use the below one-liner:

$ ifconfig | egrep -i flags\|ether | awk '{ FS = "flags" ; printf("%s", $1); }' | perl -p -e's/\W|ether|://g'

Here’s a brief explanation of that shell command. Firstly, we run ifconfig and grep out the lines with the interface name; the lines with the mac addresses on them. This will give you all interface names, even ones that don’t have a mac address. Then we run it through awk to mush it all on one line and cut out the cruft from the interface lines. Finally, perl is used to remove colons, whitespace, and the word “ether”.

Above are just a few ways of accomplishing this task. These are some pretty solid ways of getting a unique ID off of each machine; however, like most things in the software world, none of these are truly immutable. There are ways of getting around those machine IDs and spoofing your own–which are not exactly common or trivial–but unfortunately for the software pirate, these methods are useless without direct access to Serial Sense’s databases. In the rare scenario where an end user alters their network hardware or attempts to trick the system, your applications that have correctly implemented Serial Sense will ask the end user to activate their product again.

This entry was posted in Implementation. Bookmark the permalink.

3 Responses to Generating Unique Machine IDs

  1. rgenito says:

    Great information here :) I have written a follow up article for WordPress developers who may be interested in another method: WordPress Unique Machine IDs

  2. Doug says:

    On MacOS, you can greatly speed up the system_profiler by telling it to look in the right place.

    Add: “SPHardwareDataType” after “system_profiler” per example below:

    $ system_profiler SPHardwareDataType | grep -i "Serial Number (system):" | awk '{print $4}'

  3. NTN says:

    ioreg -ld 2 | grep -i IOPlatformSerialNumber | awk ‘{ print $3; }’

    is an alternative on MAC

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This site is using OpenAvatar based on