realbasic-nug
[Top] [All Lists]

Re: Mac Serial Number

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Mac Serial Number
From: Phil M <phil at mobleybros dot com>
Date: Fri, 18 Feb 2005 10:52:58 -0800
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20050218153111 dot 84ECE734A3B at lists dot realsoftware dot com> <b4f6351fc8a30329466ebcc03aebaac8 at scriptsoftware dot com> <e73d29f3396424d24deb7fb309500c17 at mobleybros dot com>
On Feb 18, 2005, at 8:40 AM, Phil M wrote:

On another side note, the serial number of the Mac is stored on the Hard Drive, so if you swap Hard Drives or reformat it, it may not have the serial number. I personally have partitioned my drive and now my machine does not have a serial number [except the one printed on the underside].

I do not believe that this is true (but I could be wrong). Nearly every Mac I have ever owned or managed at work has had all hard drives removed (swapped), partitioned, reformatted and so on. I have never had a Macintosh which lost it's serial number. I have a G4 400 at home which no longer has the factory 10 GB drive installed, but is replaced with a 60 GB. And when I install new hard drives, I do a clean install of the OS and applications.

Further research seems that Sam Rowlands is more right. There is a very old Apple developer article from 1998 which states that there is no unique hardware or software serial number, but offers alternative suggestions:

    http://devworld.apple.com/technotes/tn/tn1103.html

Several of the suggestions in this article are very easy to get with REALbasic. For example...

Hard drive creation date:

  d = Volume(0).CreationDate

System Folder Directory ID: (not very useful though)

  i = Volume(0).Child("System Folder").MacDirID

MAC address(es):

  Dim nio As NetworkInterface
  Dim k As Integer
  Dim s() As String

  For k = 0 To (System.NetworkInterfaceCount - 1)
    nio = System.GetNetworkInterface(k)
    s.Append(nio.MACAddress)
  Next

Hard Disk Serial Number:

Use a similar trick as with the Shell "system_profiler"; there is also sample c code provided in the link above

Gestalt Machine type: (seems useless with modern computers)

  Dim resultByRefInt As Integer
  Call System.Gestalt("mach", resultByRefInt)

Gestalt Keyboard type:

  Dim resultByRefInt As Integer
  Call System.Gestalt("kbd ", resultByRefInt)

Other useful Gestalt codes:

  "bclk" = Bus clock speed: Returns the main I/O bus clock speed in Hz
  "cput" = CPU type: family model number based on a lookup table
"dplv" = Display Manager Version: Returns the Version Number of the Display Manager "ram " = Physical RAM size: bytes of the physical RAM currently installed

For a complete list of Gestalt codes and meanings:

http://developer.apple.com/documentation/Carbon/Reference/ Gestalt_Manager/gestalt_refchap/ConstantsIndex.html

Other ways to uniquely identify a Mac OS X computer...

Active User's login name:

  s = System.EnvironmentVariable("LOGNAME")

Active User's directory (as String):

  s = System.EnvironmentVariable("HOME")

Active User's Home folder Directory ID:

  Dim f As FolderItem
  Dim id As Integer

  f = New FolderItem(System.EnvironmentVariable("HOME"))
  id = f.MacDirID

Active Desktop folder Directory ID:

  Dim id As Integer
  id = DesktopFolder.MacDirID

There are a ton of other tricks which you can do, but it can be a challenge to pick items which will not change.

In the case of the network MAC ID, if the Airport Card is not enabled *and* connected, it will not report a MAC address (from my simple tests). So you cannot always count on the fact that the MAC addresses will always be available. But if at least one MAC addresses matches at least one of the ones stored in the registration file, you can count the MAC address as a match. But since this is not reliable, you need additional tests.

Here is what I would do... I would take about 10 items listed above and make certain that at least 7 are verified.

1.  MAC address.
2.  System.EnvironmentVariable("LOGNAME")
3.  DesktopFolder.MacDirID
4. System.Gestalt("bclk", resultByRefInt) : For some G5's this *might* be variable
5.  System.Gestalt("cput", resultByRefInt)
6.  System.Gestalt("kbd ", resultByRefInt)
7.  System.Gestalt("ram ", resultByRefInt)
8.  Volume(0).CreationDate
9.  Get Mac Serial Number via Shell and "system_profiler"
10. Get ATA Hard Drive serial number(s) via Shell and "system_profiler"

In the file which is used as the Registration Key file, I would not store the plain text versions of all of this info. In fact, I would probably convert each item to MD5 hashes, and in the case of NetworkInterfaces or ATA serial numbers I would store an array of MD5 hashes.

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>