Last active
August 18, 2022 21:02
-
-
Save pudquick/c7dd1262bd81a32663f0 to your computer and use it in GitHub Desktop.
Get Mac's serial number, hardware UUID, and board-id via python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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".encode("utf-8"))), keyname, None, 0) | |
def get_hardware_uuid(): | |
return io_key("IOPlatformUUID".encode("utf-8")) | |
def get_hardware_serial(): | |
return io_key("IOPlatformSerialNumber".encode("utf-8")) | |
def get_board_id(): | |
return str(io_key("board-id".encode("utf-8"))).rstrip('\x00') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated version that is both python2 and python3 compatible (assuming pyobjc available for python3):