使用Python查找Mac UUID/序列号
基本上,我计划将计算机的UUID/序列号绑定到运行它的密钥上,在windows上,我发现获取UUID非常容易,但是我很难为Mac获得任何东西。使用Python查找Mac UUID/序列号,python,macos,uuid,Python,Macos,Uuid,基本上,我计划将计算机的UUID/序列号绑定到运行它的密钥上,在windows上,我发现获取UUID非常容易,但是我很难为Mac获得任何东西。 有什么解决方案吗?MacOS有一个用于访问此信息的内置程序,您可以使用 system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{print $4}' 如果您在python中明确需要这个字符串(如果您使用的是3.5+),则可以使用该模块 下面是我如何通过Python获取Mac系列
有什么解决方案吗?MacOS有一个用于访问此信息的内置程序,您可以使用
system_profiler SPHardwareDataType | grep 'Serial Number' | awk '{print $4}'
如果您在python中明确需要这个字符串(如果您使用的是3.5+),则可以使用该模块
下面是我如何通过Python获取Mac系列的:
import subprocess
task = subprocess.Popen(
['system_profiler', 'SPHardwareDataType'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
out, err = task.communicate()
for l in out.split('\n'):
if 'Serial Number (system)' in l:
serial_line = l.strip()
break
serial = serial_line.split(' ')[-1]
print(serial)
可在此处找到pyobjc方法:
import subprocess
task = subprocess.Popen(
['system_profiler', 'SPHardwareDataType'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
out, err = task.communicate()
for l in out.split('\n'):
if 'Serial Number (system)' in l:
serial_line = l.strip()
break
serial = serial_line.split(' ')[-1]
print(serial)