Mac OS X 中的唯一硬件 ID
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++。
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++.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
对于 C/C++:
For C/C++:
尝试这个终端命令:
来自 这里
这是用 Cocoa 封装的命令(可以可能会变得更干净一点):
Try this Terminal command:
From here
Here is that command wrapped in Cocoa (which could probably be made a bit cleaner):
为什么不尝试 gethostuuid() 呢? 以下是 Mac OS X 系统调用手册中的文档:
名称:
概要:
描述:
返回值:
错误
Why not try
gethostuuid()
? Here's the documentation from the Mac OS X System Calls Manual:NAME:
SYNOPSIS:
DESCRIPTION:
RETURN VALUES:
ERRORS
如果您告诉我们您使用的是什么语言,这个问题会更容易回答。 这些信息无需任何 shell 命令即可通过 SystemConfiguration 框架获取,如果您想亲自动手,也可以通过 IOKit 获取该信息。
This would be easier to answer if you told us what language you were using. The information is obtainable without any shell commands through the SystemConfiguration framework, and also through IOKit if you want to get your hands really dirty.
运行:
在终端中返回可能是唯一的 id。 这适用于我的 10.5 机器,我不确定其他版本的 OS X 中正确的字符串是什么。
Running:
in a terminal returns what it likely a unique id. That works on my 10.5 box, I'm not sure what the correct string will be in other versions of OS X.
正如上面一些人所暗示的,您可以使用终端命令来获取硬件 ID。
我假设你想在代码中执行此操作,所以我会看一下 Cocoa 中的 NSTask 类。 它基本上允许您在应用程序内运行终端命令。
这段代码是如何在 Cocoa 中使用 NSTask 的示例。 它设置执行“killall”命令的环境。 它传递给它的参数“Finder”。
这相当于在命令行上运行“killall Finder”,这显然会杀死 Finder。
As some people above have hinted, you can use a Terminal command to get a hardware ID.
I assume you want to do this in code however so I would take a look at the NSTask class in Cocoa. It basically lets you run terminal commands inside your application.
This code is an example of how to use NSTask in Cocoa. It sets up the environment to execute the "killall" command. It passes it the arguement "Finder".
It's the equivilent of running "killall Finder" on the command line, which will kill the Finder obviously.
以下命令与 ioreg 命令等效且简单得多。
system_profiler SPHardwareDataType | 系统分析器 awk '/UUID/ { print $3 }
The following is equivalent and far simpler than the ioreg command.
system_profiler SPHardwareDataType | awk '/UUID/ { print $3 }
系统分析器(在应用程序 - 实用程序中)包含大部分此类信息。 它有您的序列号和 mac 地址(与 Mac 无关。所有计算机都有一个 mac 地址,对于每个网卡来说几乎都是唯一的)。
System Profiler (in Applications - Utilities) contains most of this kind of info. It has your serial number and your mac address (no relation to Mac. All computers have a mac address which is pretty much unique to every network card).