Skip to content

Instantly share code, notes, and snippets.

@carlosmemorandum
Forked from angeloped/get_serial_number.py
Created June 25, 2020 07:57
Show Gist options
  • Save carlosmemorandum/47c75d3ee02ae8af45974a1f8504e0bd to your computer and use it in GitHub Desktop.
Save carlosmemorandum/47c75d3ee02ae8af45974a1f8504e0bd to your computer and use it in GitHub Desktop.
Python code to get motherboard serial number. For Linux, MacOS, and Windows.
# wmic bios get serialnumber#Windows
# hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid#Linux
# ioreg -l | grep IOPlatformSerialNumber#Mac OS X
import os, sys
def getMachine_addr():
os_type = sys.platform.lower()
if "win" in os_type:
command = "wmic bios get serialnumber"
elif "linux" in os_type:
command = "hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid"
elif "darwin" in os_type:
command = "ioreg -l | grep IOPlatformSerialNumber"
return os.popen(command).read().replace("\n","").replace(" ","").replace(" ","")
#output machine serial code: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX
print(getMachine_addr())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment