Getting a unique hardware ID with Python

后端 未结 5 1448
野的像风
野的像风 2020-12-16 04:45

I have a process that requires me to identify different machines, and I\'m not sure what\'s the best way to do it. I do not want to save that ID on a text file or something,

相关标签:
5条回答
  • 2020-12-16 05:14

    For windows this seems to get same uuid every time por each device based on the MAC address:

    str(uuid.uuid1(uuid.getnode(),0))[24:]

    But it does not seem to keep same ID on Android 4.4.2.

    0 讨论(0)
  • 2020-12-16 05:24

    or use bios serialnr

    wmic bios get serialnumber
    
    0 讨论(0)
  • 2020-12-16 05:27

    The ideal approach which I resorted to was this. It is quite fast and efficient.

    hwid = str(subprocess.check_output(
        'wmic csproduct get uuid')).split('\\r\\n')[1].strip('\\r').strip()
    data = requests.get(
        'https://gist.githubusercontent.com/rishav394/z/raw/x')
    if hwid in data.text:
        print('Authenticated!')
        auth = True
    else:
        print(hwid + ' was not found on the server.\nNot authorised!')
    
    0 讨论(0)
  • 2020-12-16 05:34

    Please note that you can get the same UUID from Windows without installing any additional software with the following command:

    C:\> wmic csproduct get uuid
    
    0 讨论(0)
  • 2020-12-16 05:35

    You could use dmidecode.

    Linux:

    import subprocess
    
    def get_id():
        return subprocess.Popen('hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid'.split())
    

    Windows:
    NOTE: Requires dmidecode for Windows

    import subprocess
    
    def get_id():
        return subprocess.Popen('dmidecode.exe -s system-uuid'.split())
    

    Cross-platform:
    NOTE: Requires dmidecode for Windows

    import subprocess
    import os
    
    def get_id():
        if 'nt' in os.name:
            return subprocess.Popen('dmidecode.exe -s system-uuid'.split())
        else:
            return subprocess.Popen('hal-get-property --udi /org/freedesktop/Hal/devices/computer --key system.hardware.uuid'.split())
    
    0 讨论(0)
提交回复
热议问题