Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Python查找Mac UUID/序列号_Python_Macos_Uuid - Fatal编程技术网

使用Python查找Mac UUID/序列号

使用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系列

基本上,我计划将计算机的UUID/序列号绑定到运行它的密钥上,在windows上,我发现获取UUID非常容易,但是我很难为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)