0

I need to generate license for each software I distribute in the market. And I will store that license and computer unique id in my server database. So,

  1. What is the Computer's Unique Id in present?
  2. How to get it in Python-3

I Googled for it, but most answers I got is taking MAC Id, nowdays anyone can change the MAC Id.So, What is the best id that cannot be changed and is visible in Python-3

Deoj
  • 71
  • 1
  • 5
  • Can I get comments, why my question is downvoted...? – Deoj Sep 11 '18 at 18:31
  • Not the downvoter but your question is super broad, super opinionated and frankly seems like just a "give me the code" type of question. The first two are not well fitted for this site and the last one is not well received in this community. Just my thought I guess. Also your first question doesn't make sense, are you asking how to generate a unique id for each computer that wants your software? which is also very opinionated and broad. – MooingRawr Sep 11 '18 at 18:32
  • I haven't asked for the full codes...Nor I'm fully depend on it as I have made small research before posting question...I just want to know what will be the unique id that can be visible in python... – Deoj Sep 11 '18 at 18:36
  • There isn't really a unique id. Most people try to generate a mostly unique fingerprint, [like this question](https://stackoverflow.com/questions/16858782/how-to-obtain-almost-unique-system-identifier-in-a-cross-platform-way) by examining the machines hardware. Are you targeting just windows machines? You might be able to use the license id for the OS. – Patrick Haugh Sep 11 '18 at 18:36
  • No, reply to your edit @MooingRawr . I want computer's unique id, not the one created by me... – Deoj Sep 11 '18 at 18:37
  • Yes @PatrickHaugh , I am just targeting windows machines... – Deoj Sep 11 '18 at 18:38
  • You are asking 2 questions and the first is a general one that you can be find already answered for example here https://stackoverflow.com/questions/3443093/what-is-a-good-unique-pc-identifier – abc Sep 11 '18 at 18:39
  • @PatrickHaugh the question you linked is for C language and I need it for Python-3 – Deoj Sep 11 '18 at 18:46
  • Any updates...? – Deoj Sep 12 '18 at 11:31

2 Answers2

3

If you want the unique ID of a Windows Machine, meaning the UUID, here's a simple function to get it:

import subprocess
def GetUUID():
    cmd = 'wmic csproduct get uuid'
    uuid = str(subprocess.check_output(cmd))
    pos1 = uuid.find("\\n")+2
    uuid = uuid[pos1:-15]
    return uuid
print(GetUUID())
krypterro
  • 391
  • 1
  • 3
  • 14
  • Is it fixed for all the computers? – Deoj Sep 12 '18 at 11:28
  • Here's the info on the UUID used by MS: https://en.wikipedia.org/wiki/UUID but the short answer is yes. It's generally what's used within the MS eco-systems for this purpose, so in the code above I just reached into the MS command line to get the UUID from there and pulled it into Python. As long as you just need to run your application on Microsoft Windows machines, this will work fine. – krypterro Sep 12 '18 at 17:11
3

A lot of anwsers is so naive and complicated, I googled a lot and I can not get a satisfiying answer. So here is my conclusion:

  • for UUID:

     from wmi import WMI
     from sys import platform
    
     def get_device_uuid():
      if platform == "linux" or platform == "linux2":
          # linux
    
      elif platform == "darwin":
          # OS X
      elif platform == "win32":
          return WMI().Win32_ComputerSystemProduct()[0].UUID
    
  • for device name:

    def get_device_name():
      if platform == "linux" or platform == "linux2":
          my_system = platform.uname()
          return '{}-{}'.format(my_system.system, my_system.node)
      elif platform == "darwin":
          my_system = platform.uname()
          return '{}-{}'.format(my_system.system, my_system.node)
      elif platform == "win32":
          a = WMI().Win32_ComputerSystemProduct()[0]
          return '{}-{}'.format(a.Manufacturer, a.Name)
    
Nicholas Jela
  • 2,540
  • 7
  • 24
  • 40