Created
May 4, 2016 14:01
-
-
Save cr0hn/6ad1b51cc79959ef0a3d05acdce47ca7 to your computer and use it in GitHub Desktop.
Get unique hardware ID (and always the same) based on CPU-info
This file contains hidden or 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
# | |
# Author: Daniel Garcia (cr0hn) - @ggdaniel | |
# License: BSD | |
# | |
# Dependencies: py-cpuinfo (pip install py-cpuinfo) | |
# | |
def get_hardware_id(): | |
""" | |
Get an unique hardware ID, based on CPU info. All the times called, the value will be the same. | |
>>> get_hardware_id() | |
'f8ef57d64aae6f3c45200b39di422bd6ca625d9a79655cb3aa6e171ef6f93013aa16c2df2f2b0359dfaf1782ba6fda94300506cdd9b21fdaf1264fbd0e47abb89' | |
:return: string with the hardware ID | |
:rtype: str | |
""" | |
import cpuinfo | |
_ci = cpuinfo.get_cpu_info() | |
cpu_inf = ("%s%s%s%s" % (_ci['hz_actual'], | |
_ci['brand'], | |
"".join(_ci['flags']), | |
_ci['arch'])).replace(" ", "") | |
d = hashlib.sha512() | |
d.update(cpu_inf.encode(errors="ignore")) | |
return d.hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment