使用Python查找Mac UUID/序列号 [英] Using Python to find Mac UUID/Serial Number
本文介绍了使用Python查找Mac UUID/序列号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
基本上,我打算将计算机的UUID/序列号与运行时的密钥绑定在一起,在Windows上,我发现使UUID变得很容易,但是我一直在为Mac买东西.有解决方案吗?
Basically I was planning on tying the computers UUID/Serial number to the key which it is ran with, On windows I found getting the UUID easy enough however I am struggling to get anything for Mac. Any solutions?
推荐答案
MacOS有一个内置程序用于访问此信息,您可以使用
MacOS has a built-in program for accessing this information and you can fetch it with
system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{print $4}'
如果您明确需要在python中使用此字符串(并且如果使用的是3.5+),则可以使用
If you explicitly needed this string inside python (and if you're using 3.5+) you could use the subprocess
module
import subprocess
cmd = "system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{print $4}'"
result = subprocess.run(cmd, stdout=subprocess.PIPE, shell=True, check=True)
serial_number = result.stdout.strip()
这篇关于使用Python查找Mac UUID/序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文