Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unique hardware ID in Mac OS X

Mac OS X development is a fairly new animal for me, and I'm in the process of porting over some software. For software licensing and registration I need to be able to generate some kind of hardware ID. It doesn't have to be anything fancy; Ethernet MAC address, hard drive serial, CPU serial, something like that.

I've got it covered on Windows, but I haven't a clue on Mac. Any idea of what I need to do, or where I can go for information on this would be great!

Edit:

For anybody else that is interested in this, this is the code I ended up using with Qt's QProcess class:

QProcess proc;  QStringList args; args << "-c" << "ioreg -rd1 -c IOPlatformExpertDevice |  awk '/IOPlatformUUID/ { print $3; }'"; proc.start( "/bin/bash", args ); proc.waitForFinished();  QString uID = proc.readAll(); 

Note: I'm using C++.

like image 644
Gerald Avatar asked Jun 01 '09 03:06

Gerald


People also ask

Where can I find Hwid on Mac?

Open System Preferences and click the Network button. Click the "Show" drop down menu and select "Built-in Ethernet." Make sure the "TCP/IP" tab is selected. Your Ethernet Hardware ID should be displayed.

What is hardware UUID?

Stands for "Universally Unique Identifier." A UUID is a 128-bit number used to identify a unique object on a computer system. Examples include objects in software programs, parameters in URLs, and labels of individual hardware devices.

How do I know if Mac has Systeminfo?

To open a system report, choose Apple menu > About This Mac, then click System Report. Tip: You can also press and hold the Option key, then choose Apple menu > System Information. To change your view of the report, do one of the following: See a longer report: Choose File > Show More Information.

How do I find the name of my imac?

If you're sharing your computer's screen or files, other users on your network can find your Mac by looking for its computer name. On your Mac, choose Apple menu > System Preferences, then click Sharing . The computer name for your Mac appears at the top of Sharing preferences.


2 Answers

For C/C++:

void get_platform_uuid(char * buf, int bufSize) {     io_registry_entry_t ioRegistryRoot = IORegistryEntryFromPath(kIOMasterPortDefault, "IOService:/");     CFStringRef uuidCf = (CFStringRef) IORegistryEntryCreateCFProperty(ioRegistryRoot, CFSTR(kIOPlatformUUIDKey), kCFAllocatorDefault, 0);     IOObjectRelease(ioRegistryRoot);     CFStringGetCString(uuidCf, buf, bufSize, kCFStringEncodingMacRoman);     CFRelease(uuidCf);     } 
like image 169
yairchu Avatar answered Sep 21 '22 01:09

yairchu


Try this Terminal command:

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

From here

Here is that command wrapped in Cocoa (which could probably be made a bit cleaner):

NSArray * args = [NSArray arrayWithObjects:@"-rd1", @"-c", @"IOPlatformExpertDevice", @"|", @"grep", @"model", nil]; NSTask * task = [NSTask new]; [task setLaunchPath:@"/usr/sbin/ioreg"]; [task setArguments:args];  NSPipe * pipe = [NSPipe new]; [task setStandardOutput:pipe]; [task launch];  NSArray * args2 = [NSArray arrayWithObjects:@"/IOPlatformUUID/ { split($0, line, \"\\\"\"); printf(\"%s\\n\", line[4]); }", nil]; NSTask * task2 = [NSTask new]; [task2 setLaunchPath:@"/usr/bin/awk"]; [task2 setArguments:args2];  NSPipe * pipe2 = [NSPipe new]; [task2 setStandardInput:pipe]; [task2 setStandardOutput:pipe2]; NSFileHandle * fileHandle2 = [pipe2 fileHandleForReading]; [task2 launch];  NSData * data = [fileHandle2 readDataToEndOfFile]; NSString * uuid = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; 
like image 32
xyz Avatar answered Sep 20 '22 01:09

xyz