Skip to content

Instantly share code, notes, and snippets.

@LcTrKiD
Forked from erikng/get_platform.py
Created February 6, 2020 14:01
Show Gist options
  • Save LcTrKiD/e3c0376d81ddb60af047c36fad00380c to your computer and use it in GitHub Desktop.
Save LcTrKiD/e3c0376d81ddb60af047c36fad00380c to your computer and use it in GitHub Desktop.
Get Mac's serial number and hardware UUID via python
import objc
from Foundation import NSBundle
IOKit_bundle = NSBundle.bundleWithIdentifier_('com.apple.framework.IOKit')
functions = [("IOServiceGetMatchingService", b"II@"),
("IOServiceMatching", b"@*"),
("IORegistryEntryCreateCFProperty", b"@I@@I"),
]
objc.loadBundleFunctions(IOKit_bundle, globals(), functions)
def io_key(keyname):
return IORegistryEntryCreateCFProperty(IOServiceGetMatchingService(0, IOServiceMatching("IOPlatformExpertDevice")), keyname, None, 0)
def get_hardware_uuid():
return io_key("IOPlatformUUID")
def get_hardware_serial():
return io_key("IOPlatformSerialNumber")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment