mac.py 950 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #coding=utf-8
  2. import uuid
  3. import datetime
  4. import os
  5. import platform
  6. import base64
  7. import hashlib
  8. XorKey = [0xB2, 0x09, 0xBB, 0x55, 0x93, 0x83, 0x03, 0x24]
  9. def enc(src):
  10. j, result = 0, ""
  11. for s in src:
  12. result = result + hex(ord(s) ^ (XorKey[j]))[2:]
  13. j = (j + 1) % 8
  14. return result
  15. sysstr = platform.system()
  16. if (sysstr == "Windows"):
  17. import winreg
  18. key = winreg.OpenKey(
  19. winreg.HKEY_LOCAL_MACHINE,
  20. "SOFTWARE\\Microsoft\\Cryptography",
  21. 0,
  22. winreg.KEY_READ | winreg.KEY_WOW64_64KEY
  23. )
  24. result = winreg.QueryValueEx(key, "MachineGuid")
  25. mac = result[0]
  26. else:
  27. mac = ':'.join(['{:02x}'.format((uuid.getnode() >> i) & 0xff) for i in range(0,8*6,8)][::-1])
  28. path = '/auth/kaohe/v2/'
  29. mac += 'ZZLY[' + path + ']20190325'
  30. mac = enc(mac)
  31. mac = base64.b64encode(mac.encode())
  32. mac = hashlib.sha256(mac).hexdigest()
  33. with open('key', mode='wb') as f:
  34. f.write(mac.encode('utf-8'))