Skip to content

Instantly share code, notes, and snippets.

@dderusha
Forked from pudquick/get_platform.py
Created January 26, 2018 01:21
Show Gist options
  • Save dderusha/c0a729492a0c6e36229ae18b8f79bf38 to your computer and use it in GitHub Desktop.
Save dderusha/c0a729492a0c6e36229ae18b8f79bf38 to your computer and use it in GitHub Desktop.
Get Mac's serial number, hardware UUID, and board-id 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")
def get_board_id():
return str(io_key("board-id")).rstrip('\x00')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment