1

Requirement: no apple developer account.

I don't care about iOS devices. Only a unique id of a Mac (iMac, Mac mini and Macbook) is needed.

I have used this approach but it does't work any more on some latest Mac:

ioreg -rd1 -c IOPlatformExpertDevice | awk '/IOPlatformUUID/ { split($0, line, "\""); printf("%s\n", line[4]); }'

Why I think it doesn't work?
I have got some feedbacks from my clients that this approach get some random number. And I have checked the IDs my server received: Yes, they are random numbers (maybe it is regenerated after the Mac restarts).

So my question is:
How to get an unique id of a Mac now in 2018? Approaches that doesn't demand writting Objective-C or C++ code are preferred.

I'm trying to get the ID in C#: Mono, Unity3D or Xamarin.

zwcloud
  • 4,546
  • 3
  • 40
  • 69
  • 7
    When you say "it doesn't work any more", does it throw an error? Does it just return something non-unique? – Adam V Jan 05 '18 at 15:18
  • Did you try any of the other approaches from there, and what language are you looking for? The code in the next answer down answer that goes via `SCNetworkInterfaceCopyAll` shows a plain C interface in use, albeit wrapped up in Objective-C in that answer. There's no actual need to [toll-free] bridge the `CFArray`, etc, to Objective-C types, it's just easier for people who use that language. Is it C you were looking for? – Tommy Jan 05 '18 at 15:21
  • I have got some feedbacks from my clients that this approach get some random number. And I have verfied the IDs I received in my server: Yes, they are random numbers. @AdamV – zwcloud Jan 05 '18 at 15:23
  • 1
    `NSTask` is not needed. You can parse IOReg directly with the APIs `IOServiceMatching`, `IOServiceGetMatchingService` and `IORegistryEntryCreateCFProperty` passing key `kIOPlatformUUIDKey` in the `IOKit` framework – vadian Jan 05 '18 at 15:23
  • @Tommy Thanks! The random number phenomenon doesn't happen on my Mac. So I haven't tried other approaches for now. I have updated the question: I'm trying to find a C# solution. – zwcloud Jan 05 '18 at 15:31
  • @vadian Thanks for the tip. But that doesn't solve the problem. A new approach is needed. – zwcloud Jan 05 '18 at 15:33
  • Another downvote. WOW~ I'm not asking why it doesn't work. This problem only happens on some clients' computer. edited the question to clarify that. – zwcloud Oct 08 '19 at 03:02

1 Answers1

1

In Terminal.app you can get information via system_profiler, e.g. for a UUID:

system_profiler SPHardwareDataType | awk '/UUID/ {print $3}'

or the Macs serial number, which should not be randomized:

system_profiler SPHardwareDataType | awk '/Serial/ {print $4}'
mschmidt
  • 2,740
  • 4
  • 17
  • 31