Mac OS X中的唯一硬件ID [英] Unique hardware ID in Mac OS X
问题描述
Mac OS X开发对我来说是一个相当新的动物,我正在移植一些软件。对于软件许可和注册,我需要能够生成某种硬件ID。它不必是什么幻想;以太网MAC地址,硬盘驱动器串行,CPU串行,类似的东西。
我已经在Windows上覆盖,但我没有在Mac上的线索。任何想法,我需要做什么,或在哪里可以去这方面的信息将是伟大的!
编辑:
对此感兴趣的任何人,这是我最后使用的代码Qt的QProcess类:
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();
注意:我使用的是C ++。
尝试此终端命令:
ioreg -rd1 -c IOPlatformExpertDevice | awk'/ IOPlatformUUID / {split($ 0,line,\); printf(%s\\\
pre>
,line [4]);}'
从这里
这个命令包裹在Cocoa(可能会更清楚一点):
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\\\\
\,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];
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++.
解决方案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];
这篇关于Mac OS X中的唯一硬件ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!