Coder Social home page Coder Social logo

py-kms's Introduction

Readme

repo-size open-issues last-commit docker-status docker-pulls read-the-docs


History

py-kms is a port of node-kms created by cyrozap, which is a port of either the C#, C++, or .NET implementations of KMS Emulator. The original version was written by CODYQX4 and is derived from the reverse-engineered code of Microsoft's official KMS.

Features

  • Responds to v4, v5, and v6 KMS requests.
  • Supports activating:
    • Windows Vista
    • Windows 7
    • Windows 8
    • Windows 8.1
    • Windows 10 ( 1511 / 1607 / 1703 / 1709 / 1803 / 1809 )
    • Windows 10 ( 1903 / 1909 / 20H1 )
    • Windows Server 2008
    • Windows Server 2008 R2
    • Windows Server 2012
    • Windows Server 2012 R2
    • Windows Server 2016
    • Windows Server 2019
    • Microsoft Office 2010 ( Volume License )
    • Microsoft Office 2013 ( Volume License )
    • Microsoft Office 2016 ( Volume License )
    • Microsoft Office 2019 ( Volume License )
    • It's written in Python (tested with Python 3.6.9).
    • Supports execution by Docker, systemd, Upstart and many more...
    • Includes a GUI for simple managing.
    • Uses sqlite for persistent data storage.

Documentation

The wiki has been completly reworked and is now available on readthedocs.com. It should you provide all necessary information how to setup and to use py-kms , all without clumping this readme. The documentation also houses more details about activation with py-kms and how to get GVLK keys.

Quick start

  • To start the server, execute python3 pykms_Server.py [IPADDRESS] [PORT], the default IPADDRESS is 0.0.0.0 ( all interfaces ) and the default PORT is 1688. Note that both the address and port are optional. It's allowed to use IPv4 and IPv6 addresses. If you have a IPv6-capable dual-stack OS, a dual-stack socket is created when using a IPv6 address.
  • To start the server automatically using Docker, execute docker run -d --name py-kms --restart always -p 1688:1688 pykmsorg/py-kms.
  • To show the help pages type: python3 pykms_Server.py -h and python3 pykms_Client.py -h.
  • For launching py-kms GUI make the file pykms_Server.py executable with chmod +x /path/to/folder/py-kms/pykms_Server.py, then simply run pykms_Server.py by double-clicking.

License

  • py-kms is Unlicense
  • py-kms GUI is MIT © Matteo ℱan

py-kms's People

Contributors

angrynoodlez avatar bruor avatar edgeyboy avatar pvgoran avatar saltspork avatar seia-soto avatar simonmicro avatar speedst3r avatar systemrage avatar taknok avatar thedevfreak avatar vosdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py-kms's Issues

TabError: inconsistent use of tabs and spaces in indentation

Commit 750713d has introduced an error in pykms_Misc.py:

Traceback (most recent call last):

  File "pykms_Server.py", line 23, in <module>
    import pykms_RpcBind, pykms_RpcRequest
  File "/home/py-kms/py-kms/pykms_RpcRequest.py", line 6, in <module>
    import pykms_Base
  File "/home/py-kms/py-kms/pykms_Base.py", line 238, in <module>
    import pykms_RequestV4, pykms_RequestV5, pykms_RequestV6, pykms_RequestUnknown
  File "/home/py-kms/py-kms/pykms_RequestUnknown.py", line 6, in <module>
    from pykms_Misc import ErrorCodes
  File "/home/py-kms/py-kms/pykms_Misc.py", line 88
    except AttributeError:
                         ^
TabError: inconsistent use of tabs and spaces in indentation

Committer has used spaces to indent lines 87-90 whilst the rest of the file uses tab indentation.

100% CPU usage

   PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
 32911 root       20   0 40608 19624  8136 S 100.  0.2  2:07.29 /usr/bin/python3 pykms_Server.py 0.0.0.0 1688 -l 1033 -c 26 -a 120 -r 10080 -w 364F463A8863D35F -V ERROR
 32925 root       20   0 40608 19624  8136 R 100.  0.2  2:06.50 /usr/bin/python3 pykms_Server.py 0.0.0.0 1688 -l 1033 -c 26 -a 120 -r 10080 -w 364F463A8863D35F -V ERROR

constant 100% CPU usage..

Error 8007007B

Error 8007007B with notification message 0xC004F056 ??

Running on Windows Server 2012 R2

I have the following scenario:

VM under VMWARE - Windows Server 2012 R2 - latest updates
Python 2.7.17(64-bit)
Python 2.7 pywin32-227
tzlocal-2.0.0-py2.py3-none-any.whl
Source files in C:\PythonScipts\py-kms-master\py-kms

When I start the pykms_Server.py the following occurs:

C:\PythonScripts\py-kms-master\py-kms>python pykms_Server.py
Exception in thread Thread-Srv:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
self.run()
File "pykms_Server.py", line 150, in run
self.server.pykms_serve()
File "pykms_Server.py", line 81, in pykms_serve
ready = selector.select(timeout)
File "C:\PythonScripts\py-kms-master\py-kms\pykms_Selectors.py", line 327, in
select
self._writers, timeout)
File "C:\PythonScripts\py-kms-master\py-kms\pykms_Selectors.py", line 128, in
_syscall_wrapper
raise SelectorError(errcode)
SelectorError:

Any suggestions?

PS

I additionally duplicated this setup on a Server 2019 Standard Edition (running as a VM) and exactly the same result.

Improve KmsDataBase.xml

Only for completeness, find missing values (and check those already present) in KmsDataBase.xml (GroupID, MinKeyId, MaxKeyId, CsvlkItems, KmsItems, SkuItems, gvlk) specially for previews.

Specifying client count causes error & program exit

Expected Behavior

When starting pykms_Server.py with the client count flag (either -c or --client-count), the provided client count value should be honored by the application and everything should run as usual.

Actual Behavior

No matter what value is given for client-count, the application writes an error message to console then exits.
e.g. for the case where -c 30 is given, the application will print argument `-c/--client-count`: invalid with: '30'. Exiting...

This is a tricky problem for Docker users since there's no option to skip the -c flag with the current Dockerfile.

Steps to Reproduce the Problem

  1. Create a new python environment with all the needed prerequisites.
  2. Clone the repo
  3. Start py-kms using /usr/bin/python3 pykms_Server.py :: 1688 -c 30

Specifications

  • Version: Cloned the repo, up to date as of commit [9d9a363]
  • Platform: Ubuntu 20.04 LTS
  • Subsystem: Python 3.9.0

SQLite errors

I came across a couple of errors running pykms_Server with SQLite - don't have the actual errors anymore but you could probably replicate them.

  1. 'os' is not defined, pykms_Sql.py, line 17. - Added 'import os', 7e40ba6
  2. 'self' is not defined, pykms_Sql.py line 78. - removed 'self' from the connection reference, 5441771

_tkinter.TclError: no display name and no $DISPLAY environment variable

after building py-kms/docker-py3-kms I am left with this error.

Recreating kms ... done
Attaching to kms 
kms    | Traceback (most recent call last): 
kms    |   File "pykms_Server.py", line 266, in <module>
kms    |     srv_main_with_gui()
kms    |   File "pykms_Server.py", line 197, in srv_main_with_gui
kms    |     root = pykms_GuiBase.KmsGui()
kms    |   File "/home/py-kms/py-kms/pykms_GuiBase.py", line 77, in __init__ 
kms    |     tk.Tk.__init__(self, *args, **kwargs)
kms    |   File "/usr/lib/python3.6/tkinter/__init__.py", line 2017, in __init__
kms    |     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
kms    | _tkinter.TclError: no display name and no $DISPLAY environment variable
kms exited with code 1

Modification to start.sh:

#!/bin/bash
# EN: Start daemons
# RU: Запуск демонов
-cd /home/py-kms/py3-kms
+cd /home/py-kms/py-kms
if [ "$SQLITE" == false ];

modifications made to the Dockerfile that still need a pull request/fix:

    py3-pygments \
    sqlite-libs \
+    python3-tkinter \
    py3-pip && \

(These changes are in PR #33)

# Set Workdir
-WORKDIR /home/py-kms/py3-kms
+WORKDIR /home/py-kms/py-kms

No IPv6 support

Server.py breaks if you use a IPv6 only hostname (Only an AAAA record, no A record) or :: instead of 0.0.0.0

# python3 pykms_Server.py :: 1688          
Exception in thread Thread-1: 
Traceback (most recent call last):
  File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
    self.run()
  File "pykms_Server.py", line 51, in run
    self.server = server_create()
  File "pykms_Server.py", line 181, in server_create
    server = socketserver.TCPServer((srv_config['ip'], srv_config['port']), kmsServer)
  File "/usr/lib/python3.6/socketserver.py", line 453, in __init__
    self.server_bind()
  File "/usr/lib/python3.6/socketserver.py", line 467, in server_bind
    self.socket.bind(self.server_address)
socket.gaierror: [Errno -9] Address family for hostname not supported

UnknownTimeZoneError on Windows with pytz installed

On Windows, auto-detecting the time zone fails, as all 3 implemented methods are Linux-specific (Windows doesn't have /etc, and doesn't name time zones according to a "Continent/City" pattern). This causes a crash with UnknownTimeZoneError whenever a timestamp is logged.

There are two parts to this issue:

  • On Windows, a different strategy is needed to find the time zone. See the "tzlocal" Python module on PyPi.
  • When time zone determination fails, it shouldn't be treated as a fatal error - just print UTC timestamps, maybe with a warning, just like when pytz is missing.

ValueError: invalid literal for int() with base 10: '

When I try to activate my Windows 10 LTSC 2019 I get the following error message on the server:

Client sending
===============> Server received RPC Bind Request !!!
Server parsing RPC Bind Request...
Server generating RPC Bind Response...
Client receiving
<=============== Server sending RPC Bind Response...
RPC Bind acknowledged !!!

Client sending
===============> Server received RPC Activation Request !!!
Server parsing RPC Activation Request...
Server processing KMS Activation Request...
----------------------------------------
Exception happened during processing of request from ('192.168.178.109', 50768)
Traceback (most recent call last):
File "/usr/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.6/socketserver.py", line 721, in __init__
self.handle()
File "server.py", line 157, in handle
res = str(handler.populate()).encode('latin-1')
File "/opt/py-kms/py3-kms/rpcBase.py", line 42, in populate
return self.generateResponse(self.parseRequest())
File "/opt/py-kms/py3-kms/rpcRequest.py", line 22, in generateResponse
responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config)
File "/opt/py-kms/py3-kms/kmsBase.py", line 327, in generateKmsResponseData
return messagehandler.executeRequestLogic()
File "/opt/py-kms/py3-kms/kmsRequestV5.py", line 71, in executeRequestLogic
responseBuffer = self.serverLogic(decrypted['request'])
File "/opt/py-kms/py3-kms/kmsBase.py", line 176, in serverLogic
count = int(kmsitem['NCountPolicy'])
ValueError: invalid literal for int() with base 10: ''

0x8007000D Error

I have tried both python2 and python3 under Windows. I ran "python server.py 127.0.0.1" and tried to activate Windows. However, Windows can not be activated. It will throw a 0x8007000D error. The py-kms I used is the latest git version.

The problem only persists when running server.py under Windows version of python. I ran py-kms under Linux and Windows can be successfully activated when the KMS server is pointed to the Linux machine.

Address family for hostname not supported.

Hi,

I've updated via git pull successfully. after restart my systemd service I got this error in the py-kms log.
Wed, 08 Jul 2020 22:24:26 ERROR Connection failed '0.0.0.0:1688': [Errno -9] Address family for hostname not supported. Exiting...
Start Command is:
/usr/bin/python3 /opt/py-kms/py-kms/pykms_Server.py -w RANDOM -F /var/log/py-kms.log -V INFO

I'm afraid I don't get it

I'm supposed to use a serial key on my Office/Windows install and tell it to go check the licence on the Raspberry Pi running on my local network, right?

Could the documentation be a bit more exhaustive?

Auto start pykms_Server.py on Raspberry Pi

Raspberry Pi uses systemd to automatically run a program when the Pi boots. I'm getting an error about, "no display name and no $DISPLAY environment variable". However, it works fine when run from a shell prompt.

/etc/systemd/system/py-kms.service

[Unit]
Description=py-kms
After=network.target

[Service]
ExecStart=/usr/bin/python3 pykms_Server.py 0.0.0.0 1688 -V DEBUG --logfile /var/log/pykms_logserver.log
WorkingDirectory=/home/pi/py-kms/py-kms
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target

sudo systemctl start py-kms.service

cat /var/log/syslog

Feb 16 14:39:16 raspberrypi systemd[1]: Started py-kms.
Feb 16 14:39:17 raspberrypi python3[13828]: Traceback (most recent call last):
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 512, in <module>
Feb 16 14:39:17 raspberrypi python3[13828]:     server_main_no_terminal()
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 445, in server_main_no_terminal
Feb 16 14:39:17 raspberrypi python3[13828]:     server_with_gui()
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 429, in server_with_gui
Feb 16 14:39:17 raspberrypi python3[13828]:     root = pykms_GuiBase.KmsGui()
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/home/pi/py-kms/py-kms/pykms_GuiBase.py", line 69, in __init__
Feb 16 14:39:17 raspberrypi python3[13828]:     tk.Tk.__init__(self, *args, **kwargs)
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
Feb 16 14:39:17 raspberrypi python3[13828]:     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Feb 16 14:39:17 raspberrypi python3[13828]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Feb 16 14:39:17 raspberrypi python3[13828]: During handling of the above exception, another exception occurred:
Feb 16 14:39:17 raspberrypi python3[13828]: Traceback (most recent call last):
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 514, in <module>
Feb 16 14:39:17 raspberrypi python3[13828]:     server_main_terminal()
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 405, in server_main_terminal
Feb 16 14:39:17 raspberrypi python3[13828]:     server_check()
Feb 16 14:39:17 raspberrypi python3[13828]:   File "pykms_Server.py", line 321, in server_check
Feb 16 14:39:17 raspberrypi python3[13828]:     logger_create(loggersrv, srv_config, mode = 'a')
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/home/pi/py-kms/py-kms/pykms_Misc.py", line 105, in logger_create
Feb 16 14:39:17 raspberrypi python3[13828]:     backupCount = 1, encoding = None, delay = 0))
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/usr/lib/python3.5/logging/handlers.py", line 150, in __init__
Feb 16 14:39:17 raspberrypi python3[13828]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/usr/lib/python3.5/logging/handlers.py", line 57, in __init__
Feb 16 14:39:17 raspberrypi python3[13828]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/usr/lib/python3.5/logging/__init__.py", line 1009, in __init__
Feb 16 14:39:17 raspberrypi python3[13828]:     StreamHandler.__init__(self, self._open())
Feb 16 14:39:17 raspberrypi python3[13828]:   File "/usr/lib/python3.5/logging/__init__.py", line 1038, in _open
Feb 16 14:39:17 raspberrypi python3[13828]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Feb 16 14:39:17 raspberrypi python3[13828]: PermissionError: [Errno 13] Permission denied: '/var/log/pykms_logserver.log'
Feb 16 14:39:17 raspberrypi systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 14:39:17 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:17 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.
Feb 16 14:39:18 raspberrypi systemd[1]: py-kms.service: Service hold-off time over, scheduling restart.
Feb 16 14:39:18 raspberrypi systemd[1]: Stopped py-kms.
Feb 16 14:39:18 raspberrypi systemd[1]: Started py-kms.
Feb 16 14:39:19 raspberrypi python3[13836]: Traceback (most recent call last):
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 512, in <module>
Feb 16 14:39:19 raspberrypi python3[13836]:     server_main_no_terminal()
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 445, in server_main_no_terminal
Feb 16 14:39:19 raspberrypi python3[13836]:     server_with_gui()
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 429, in server_with_gui
Feb 16 14:39:19 raspberrypi python3[13836]:     root = pykms_GuiBase.KmsGui()
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/home/pi/py-kms/py-kms/pykms_GuiBase.py", line 69, in __init__
Feb 16 14:39:19 raspberrypi python3[13836]:     tk.Tk.__init__(self, *args, **kwargs)
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
Feb 16 14:39:19 raspberrypi python3[13836]:     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Feb 16 14:39:19 raspberrypi python3[13836]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Feb 16 14:39:19 raspberrypi python3[13836]: During handling of the above exception, another exception occurred:
Feb 16 14:39:19 raspberrypi python3[13836]: Traceback (most recent call last):
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 514, in <module>
Feb 16 14:39:19 raspberrypi python3[13836]:     server_main_terminal()
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 405, in server_main_terminal
Feb 16 14:39:19 raspberrypi python3[13836]:     server_check()
Feb 16 14:39:19 raspberrypi python3[13836]:   File "pykms_Server.py", line 321, in server_check
Feb 16 14:39:19 raspberrypi python3[13836]:     logger_create(loggersrv, srv_config, mode = 'a')
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/home/pi/py-kms/py-kms/pykms_Misc.py", line 105, in logger_create
Feb 16 14:39:19 raspberrypi python3[13836]:     backupCount = 1, encoding = None, delay = 0))
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/usr/lib/python3.5/logging/handlers.py", line 150, in __init__
Feb 16 14:39:19 raspberrypi python3[13836]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/usr/lib/python3.5/logging/handlers.py", line 57, in __init__
Feb 16 14:39:19 raspberrypi python3[13836]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/usr/lib/python3.5/logging/__init__.py", line 1009, in __init__
Feb 16 14:39:19 raspberrypi python3[13836]:     StreamHandler.__init__(self, self._open())
Feb 16 14:39:19 raspberrypi python3[13836]:   File "/usr/lib/python3.5/logging/__init__.py", line 1038, in _open
Feb 16 14:39:19 raspberrypi python3[13836]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Feb 16 14:39:19 raspberrypi python3[13836]: PermissionError: [Errno 13] Permission denied: '/var/log/pykms_logserver.log'
Feb 16 14:39:19 raspberrypi systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 14:39:19 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:19 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.
Feb 16 14:39:19 raspberrypi systemd[1]: py-kms.service: Service hold-off time over, scheduling restart.
Feb 16 14:39:19 raspberrypi systemd[1]: Stopped py-kms.
Feb 16 14:39:19 raspberrypi systemd[1]: Started py-kms.
Feb 16 14:39:20 raspberrypi python3[13841]: Traceback (most recent call last):
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 512, in <module>
Feb 16 14:39:20 raspberrypi python3[13841]:     server_main_no_terminal()
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 445, in server_main_no_terminal
Feb 16 14:39:20 raspberrypi python3[13841]:     server_with_gui()
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 429, in server_with_gui
Feb 16 14:39:20 raspberrypi python3[13841]:     root = pykms_GuiBase.KmsGui()
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/home/pi/py-kms/py-kms/pykms_GuiBase.py", line 69, in __init__
Feb 16 14:39:20 raspberrypi python3[13841]:     tk.Tk.__init__(self, *args, **kwargs)
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
Feb 16 14:39:20 raspberrypi python3[13841]:     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Feb 16 14:39:20 raspberrypi python3[13841]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Feb 16 14:39:20 raspberrypi python3[13841]: During handling of the above exception, another exception occurred:
Feb 16 14:39:20 raspberrypi python3[13841]: Traceback (most recent call last):
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 514, in <module>
Feb 16 14:39:20 raspberrypi python3[13841]:     server_main_terminal()
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 405, in server_main_terminal
Feb 16 14:39:20 raspberrypi python3[13841]:     server_check()
Feb 16 14:39:20 raspberrypi python3[13841]:   File "pykms_Server.py", line 321, in server_check
Feb 16 14:39:20 raspberrypi python3[13841]:     logger_create(loggersrv, srv_config, mode = 'a')
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/home/pi/py-kms/py-kms/pykms_Misc.py", line 105, in logger_create
Feb 16 14:39:20 raspberrypi python3[13841]:     backupCount = 1, encoding = None, delay = 0))
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/usr/lib/python3.5/logging/handlers.py", line 150, in __init__
Feb 16 14:39:20 raspberrypi python3[13841]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/usr/lib/python3.5/logging/handlers.py", line 57, in __init__
Feb 16 14:39:20 raspberrypi python3[13841]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/usr/lib/python3.5/logging/__init__.py", line 1009, in __init__
Feb 16 14:39:20 raspberrypi python3[13841]:     StreamHandler.__init__(self, self._open())
Feb 16 14:39:20 raspberrypi python3[13841]:   File "/usr/lib/python3.5/logging/__init__.py", line 1038, in _open
Feb 16 14:39:20 raspberrypi python3[13841]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Feb 16 14:39:20 raspberrypi python3[13841]: PermissionError: [Errno 13] Permission denied: '/var/log/pykms_logserver.log'
Feb 16 14:39:20 raspberrypi systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 14:39:20 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:20 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.
Feb 16 14:39:20 raspberrypi systemd[1]: py-kms.service: Service hold-off time over, scheduling restart.
Feb 16 14:39:20 raspberrypi systemd[1]: Stopped py-kms.
Feb 16 14:39:20 raspberrypi systemd[1]: Started py-kms.
Feb 16 14:39:21 raspberrypi python3[13847]: Traceback (most recent call last):
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 512, in <module>
Feb 16 14:39:21 raspberrypi python3[13847]:     server_main_no_terminal()
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 445, in server_main_no_terminal
Feb 16 14:39:21 raspberrypi python3[13847]:     server_with_gui()
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 429, in server_with_gui
Feb 16 14:39:21 raspberrypi python3[13847]:     root = pykms_GuiBase.KmsGui()
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/home/pi/py-kms/py-kms/pykms_GuiBase.py", line 69, in __init__
Feb 16 14:39:21 raspberrypi python3[13847]:     tk.Tk.__init__(self, *args, **kwargs)
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
Feb 16 14:39:21 raspberrypi python3[13847]:     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Feb 16 14:39:21 raspberrypi python3[13847]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Feb 16 14:39:21 raspberrypi python3[13847]: During handling of the above exception, another exception occurred:
Feb 16 14:39:21 raspberrypi python3[13847]: Traceback (most recent call last):
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 514, in <module>
Feb 16 14:39:21 raspberrypi python3[13847]:     server_main_terminal()
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 405, in server_main_terminal
Feb 16 14:39:21 raspberrypi python3[13847]:     server_check()
Feb 16 14:39:21 raspberrypi python3[13847]:   File "pykms_Server.py", line 321, in server_check
Feb 16 14:39:21 raspberrypi python3[13847]:     logger_create(loggersrv, srv_config, mode = 'a')
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/home/pi/py-kms/py-kms/pykms_Misc.py", line 105, in logger_create
Feb 16 14:39:21 raspberrypi python3[13847]:     backupCount = 1, encoding = None, delay = 0))
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/usr/lib/python3.5/logging/handlers.py", line 150, in __init__
Feb 16 14:39:21 raspberrypi python3[13847]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/usr/lib/python3.5/logging/handlers.py", line 57, in __init__
Feb 16 14:39:21 raspberrypi python3[13847]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/usr/lib/python3.5/logging/__init__.py", line 1009, in __init__
Feb 16 14:39:21 raspberrypi python3[13847]:     StreamHandler.__init__(self, self._open())
Feb 16 14:39:21 raspberrypi python3[13847]:   File "/usr/lib/python3.5/logging/__init__.py", line 1038, in _open
Feb 16 14:39:21 raspberrypi python3[13847]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Feb 16 14:39:21 raspberrypi python3[13847]: PermissionError: [Errno 13] Permission denied: '/var/log/pykms_logserver.log'
Feb 16 14:39:21 raspberrypi systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 14:39:21 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:21 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.
Feb 16 14:39:21 raspberrypi systemd[1]: py-kms.service: Service hold-off time over, scheduling restart.
Feb 16 14:39:21 raspberrypi systemd[1]: Stopped py-kms.
Feb 16 14:39:21 raspberrypi systemd[1]: Started py-kms.
Feb 16 14:39:22 raspberrypi python3[13852]: Traceback (most recent call last):
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 512, in <module>
Feb 16 14:39:22 raspberrypi python3[13852]:     server_main_no_terminal()
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 445, in server_main_no_terminal
Feb 16 14:39:22 raspberrypi python3[13852]:     server_with_gui()
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 429, in server_with_gui
Feb 16 14:39:22 raspberrypi python3[13852]:     root = pykms_GuiBase.KmsGui()
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/home/pi/py-kms/py-kms/pykms_GuiBase.py", line 69, in __init__
Feb 16 14:39:22 raspberrypi python3[13852]:     tk.Tk.__init__(self, *args, **kwargs)
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__
Feb 16 14:39:22 raspberrypi python3[13852]:     self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
Feb 16 14:39:22 raspberrypi python3[13852]: _tkinter.TclError: no display name and no $DISPLAY environment variable
Feb 16 14:39:22 raspberrypi python3[13852]: During handling of the above exception, another exception occurred:
Feb 16 14:39:22 raspberrypi python3[13852]: Traceback (most recent call last):
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 514, in <module>
Feb 16 14:39:22 raspberrypi python3[13852]:     server_main_terminal()
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 405, in server_main_terminal
Feb 16 14:39:22 raspberrypi python3[13852]:     server_check()
Feb 16 14:39:22 raspberrypi python3[13852]:   File "pykms_Server.py", line 321, in server_check
Feb 16 14:39:22 raspberrypi python3[13852]:     logger_create(loggersrv, srv_config, mode = 'a')
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/home/pi/py-kms/py-kms/pykms_Misc.py", line 105, in logger_create
Feb 16 14:39:22 raspberrypi python3[13852]:     backupCount = 1, encoding = None, delay = 0))
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/usr/lib/python3.5/logging/handlers.py", line 150, in __init__
Feb 16 14:39:22 raspberrypi python3[13852]:     BaseRotatingHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/usr/lib/python3.5/logging/handlers.py", line 57, in __init__
Feb 16 14:39:22 raspberrypi python3[13852]:     logging.FileHandler.__init__(self, filename, mode, encoding, delay)
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/usr/lib/python3.5/logging/__init__.py", line 1009, in __init__
Feb 16 14:39:22 raspberrypi python3[13852]:     StreamHandler.__init__(self, self._open())
Feb 16 14:39:22 raspberrypi python3[13852]:   File "/usr/lib/python3.5/logging/__init__.py", line 1038, in _open
Feb 16 14:39:22 raspberrypi python3[13852]:     return open(self.baseFilename, self.mode, encoding=self.encoding)
Feb 16 14:39:22 raspberrypi python3[13852]: PermissionError: [Errno 13] Permission denied: '/var/log/pykms_logserver.log'
Feb 16 14:39:22 raspberrypi systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE
Feb 16 14:39:22 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:22 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.
Feb 16 14:39:23 raspberrypi systemd[1]: py-kms.service: Service hold-off time over, scheduling restart.
Feb 16 14:39:23 raspberrypi systemd[1]: Stopped py-kms.
Feb 16 14:39:23 raspberrypi systemd[1]: py-kms.service: Start request repeated too quickly.
Feb 16 14:39:23 raspberrypi systemd[1]: Failed to start py-kms.
Feb 16 14:39:23 raspberrypi systemd[1]: py-kms.service: Unit entered failed state.
Feb 16 14:39:23 raspberrypi systemd[1]: py-kms.service: Failed with result 'exit-code'.

RDP server CALs

Does py-kms allow a server with the RDP role to log in non-admin users?

Add support for Windows 10 1903

Hi,
I saw that Windows 10 1903 was released today, and so there is a need to update "KmsDataBase.xml".

How can one update the "KmsDataBase.xml" file? from where can we get the values?

Docker py-kms

Hi, friends. I like bash and docker. I write Dockerfile for SystemRage. And I want support this container, write in this issue about docker-container.

Error in windows service

Hello my issue is with the py-kms service , specifically the error is "1053"
I have already tried all recommended actions (manual install with cmd and nssm) and all necessary pip libs
All error is about the service cant respond in time.
This is my errror message :
--> C:>python kms-winservice.py start
Starting service py-kms
Error starting service: The service did not respond to the start or control request in a timely fashion.

-->C:\nssm-2.24\win32>nssm start py-kms
py-kms: START: The service did not respond to the start or control request in a timely fashion
The same message I receive when I try to start the service from servises tab.

Thank you in advance

Problems when responding a request

Im running server with python3.

SO Hosting Scritpt: Ubuntu18.04 Server

Error: ValueError: badly formed hexadecimal UUID string

SO asking KMS response: Windows10 Pro

pip3 packages:

asn1crypto (0.24.0)
attrs (17.4.0)
Automat (0.6.0)
blinker (1.4)
certifi (2018.1.18)
chardet (3.0.4)
click (6.7)
cloud-init (18.2)
colorama (0.3.7)
command-not-found (0.3)
configobj (5.0.6)
constantly (15.1.0)
cryptography (2.1.4)
distro-info (0.18)
httplib2 (0.9.2)
hyperlink (17.3.1)
idna (2.6)
incremental (16.10.1)
Jinja2 (2.10)
jsonpatch (1.16)
jsonpointer (1.10)
jsonschema (2.6.0)
keyring (10.6.0)
keyrings.alt (3.0)
language-selector (0.1)
MarkupSafe (1.0)
oauthlib (2.0.6)
PAM (0.4.2)
pip (9.0.1)
pyasn1 (0.4.2)
pyasn1-modules (0.2.1)
pycrypto (2.6.1)
pygobject (3.26.1)
PyJWT (1.5.3)
pyOpenSSL (17.5.0)
pyserial (3.4)
python-apt (1.6.2)
python-debian (0.1.32)
pytz (2018.7)
pyxdg (0.25)
PyYAML (3.12)
requests (2.18.4)
requests-unixsocket (0.1.5)
SecretStorage (2.3.1)
service-identity (16.0.0)
setuptools (39.0.1)
six (1.11.0)
ssh-import-id (5.7)
systemd-python (234)
Twisted (17.9.0)
tzlocal (1.5.1)
ufw (0.35)
unattended-upgrades (0.1)
urllib3 (1.22)
wheel (0.30.0)
zope.interface (4.3.2)

Execution:

$ python3 server.py

Client sending
===============> Server received RPC Bind Request !!!
Server parsing RPC Bind Request...
Server generating RPC Bind Response...
Client receiving
<=============== Server sending RPC Bind Response...
RPC Bind acknowledged !!!

Client sending
===============> Server received RPC Activation Request !!!
Server parsing RPC Activation Request...
Server processing KMS Activation Request...

Exception happened during processing of request from ('192.168.21.241', 49859)
Traceback (most recent call last):
File "/usr/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.6/socketserver.py", line 721, in init
self.handle()
File "server.py", line 157, in handle
res = str(handler.populate()).encode('latin-1')
File "/home/administrator/py-kms/py3-kms/rpcBase.py", line 42, in populate
return self.generateResponse(self.parseRequest())
File "/home/administrator/py-kms/py3-kms/rpcRequest.py", line 22, in generateResponse
responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config)
File "/home/administrator/py-kms/py3-kms/kmsBase.py", line 327, in generateKmsResponseData
return messagehandler.executeRequestLogic()
File "/home/administrator/py-kms/py3-kms/kmsRequestV5.py", line 71, in executeRequestLogic
responseBuffer = self.serverLogic(decrypted['request'])
File "/home/administrator/py-kms/py3-kms/kmsBase.py", line 188, in serverLogic
if uuid.UUID(skuitem['Id']) == skuId:
File "/usr/lib/python3.6/uuid.py", line 140, in init
raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadecimal UUID string

Windows 10 2004 (19041): "activated client could be detected as not genuine"

Snippet from log:

Tue, 07 Apr 2020 05:56:02 DEBUG    KMS Request: 

                                   kmsRequestStruct
                                   versionMinor: {0}
                                   versionMajor: {6}
                                   isClientVm: {0}
                                   licenseStatus: {5}
                                   graceTime: {0}
                                   applicationId:{
                                       raw: {b"4'\xc9U\x82\xd6qM\x98>\xd6\xec?\x16\x05\x9f"}
                                   }
                                   skuId:{
                                       raw: {b'\x92s\xe6-\xa7\xb7*F\xb1\xca\x10\x8d\xd1\x89\xf5\x88'}
                                   }
                                   kmsCountedId:{
                                       raw: {b'O\x13\xe2X\x11\x8e\x17M\x9c\xb2\x91\x06\x9c\x15\x11H'}
                                   }
                                   clientMachineId:{
                                       raw: [redacted]
                                   }
                                   requiredClientCount: {25}
                                   requestTime: {132307125537486265}
                                   previousClientMachineId:{
                                       raw: {b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'}
                                   }
                                   machineName: [redacted]
                                   _mnPad: {114}
                                   mnPad: [redacted]

Tue, 07 Apr 2020 05:56:02 WARNING  With count = 26, activated client could be detected as not genuine !
Tue, 07 Apr 2020 05:56:02 INFO     Machine Name: [redacted]
Tue, 07 Apr 2020 05:56:02 INFO     Client Machine ID: 51eb4481-b49e-47f0-b6e8-[redacted]
Tue, 07 Apr 2020 05:56:02 INFO     Application ID: Windows
Tue, 07 Apr 2020 05:56:02 INFO     SKU ID: Windows 10 Professional
Tue, 07 Apr 2020 05:56:02 INFO     License Status: Notifications Mode
Tue, 07 Apr 2020 05:56:02 INFO     Request Time: 2020-04-07 05:55:53 PDT (UTC-0700)
Tue, 07 Apr 2020 05:56:02 INFO     Server ePID: 03612-00206-562-132597-[redacted]
Tue, 07 Apr 2020 05:56:02 INFO     KMS V6 Response: 
...

py-kms logs in windows

Hello,

I used this tutorial to run py-kms on windows and everything works fine but I want py-kms server to create logs about computers which connected to it and activated. So, How can I do that?

**** I can not activate windows where py-kms is installed. Why?

Download and install:
https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi (into C:\Windows\Python27)
https://github.com/mhammond/pywin32/releases/download/b222/pywin32-222.win-amd64-py2.7.exe

Download and extract py-kms-master.zip into C:\Windows\Python27\py-kms
cd C:\Windows\Python27\py-kms\

Create file kms-winservice.py and put into file this code:

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import subprocess

class AppServerSvc (win32serviceutil.ServiceFramework):
svc_name = "py-kms"
svc_display_name = "py-kms"
_proc = None
_cmd = ["C:\Windows\Python27\python.exe", "C:\Windows\Python27\py-kms\server.py"]

def __init__(self,args):
    win32serviceutil.ServiceFramework.__init__(self,args)
    self.hWaitStop = win32event.CreateEvent(None,0,0,None)
    socket.setdefaulttimeout(60)

def SvcStop(self):
    self.killproc()
    self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
    win32event.SetEvent(self.hWaitStop)

def SvcDoRun(self):
    servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                          servicemanager.PYS_SERVICE_STARTED,
                          (self._svc_name_,''))
    self.main()

def main(self):
    self._proc = subprocess.Popen(self._cmd)
    self._proc.wait()

def killproc(self):
    self._proc.kill()

if name == 'main':
win32serviceutil.HandleCommandLine(AppServerSvc)
C:\Windows\Python27\python.exe kms-winservice.py install
services.msc

Find "py-kms" service and change startup type from manual to auto.
Try to start the py-kms service.
Try activate Windows Server 2008 R2 VL:
slmgr.vbs /skms 127.0.0.1
slmgr.vbs /ato

not support multiprocess use python2.6

I use it to develop multiprocess program, but i found in python2.6 use ForkingTcpServer has some problem, for example: the child process without next new request, the resource will in system to become zombie process if i use multiprocess client to request this server, that will cause so more resource wasted, how can I fix this? and the other problem is child process inherit parent socket, and i find python3.7 just allow SOCK_CLOEXEC ,how can i deal with this socket inherit issue?

KMS not responding

I tried running py-kms with python3 and 2 both give me the same error after the last git pull

`/usr/bin/python /opt/py-kms/py2-kms/server.py -s -v DEBUG
Client sending
===============> Server received RPC Bind Request !!!
Server parsing RPC Bind Request...
Server generating RPC Bind Response...
Client receiving
<=============== Server sending RPC Bind Response...
RPC Bind acknowledged !!!

Client sending
===============> Server received RPC Activation Request !!!
Server parsing RPC Activation Request...
Server processing KMS Activation Request...

Exception happened during processing of request from ('95.xx.83.xx', 42209)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 652, in init
self.handle()
File "/opt/py-kms/py2-kms/server.py", line 158, in handle
res = str(handler.populate())
File "/opt/py-kms/py2-kms/rpcBase.py", line 42, in populate
return self.generateResponse(self.parseRequest())
File "/opt/py-kms/py2-kms/rpcRequest.py", line 21, in generateResponse
responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config)
File "/opt/py-kms/py2-kms/kmsBase.py", line 329, in generateKmsResponseData
return messagehandler.executeRequestLogic()
File "/opt/py-kms/py2-kms/kmsRequestV5.py", line 71, in executeRequestLogic
responseBuffer = self.serverLogic(decrypted['request'])
File "/opt/py-kms/py2-kms/kmsBase.py", line 177, in serverLogic
count = int(kmsitem['NCountPolicy'])
ValueError: invalid literal for int() with base 10: ''

Client sending
===============> Server received RPC Bind Request !!!
Server parsing RPC Bind Request...
Server generating RPC Bind Response...
Client receiving
<=============== Server sending RPC Bind Response...
RPC Bind acknowledged !!!

Client sending
===============> Server received RPC Activation Request !!!
Server parsing RPC Activation Request...
Server processing KMS Activation Request...

Exception happened during processing of request from ('95.xx.83.xx', 59443)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 652, in init
self.handle()
File "/opt/py-kms/py2-kms/server.py", line 158, in handle
res = str(handler.populate())
File "/opt/py-kms/py2-kms/rpcBase.py", line 42, in populate
return self.generateResponse(self.parseRequest())
File "/opt/py-kms/py2-kms/rpcRequest.py", line 21, in generateResponse
responseData = kmsBase.generateKmsResponseData(request['pduData'], self.config)
File "/opt/py-kms/py2-kms/kmsBase.py", line 329, in generateKmsResponseData
return messagehandler.executeRequestLogic()
File "/opt/py-kms/py2-kms/kmsRequestV5.py", line 71, in executeRequestLogic
responseBuffer = self.serverLogic(decrypted['request'])
File "/opt/py-kms/py2-kms/kmsBase.py", line 177, in serverLogic
count = int(kmsitem['NCountPolicy'])
ValueError: invalid literal for int() with base 10: ''
----------------------------------------`

latest build python3 error when running pykms_Server.py

Module tkinter is being called but is not a default installation option with python:

apt install python3-tk resolved the issue but a default git pull and minimal system build does not contain this module.

same results with python2 running so not isolated to 3 on debian

Error below

py_kms_GuiBase.py line 16 in module import tkinter as tk
ImportError: No module named tkinter

[ Install Script ] Freenas Jail

Fpr those interested in a copy paste solution to get py-kms running.
Loosely based on my own personal script (https://github.com/Ornias1993/Freenas-Setup/blob/master/install/kms.sh)

This script creates a basic (default) jail (named "kms") and installs py-kms as a service on Freenas 11.3U1.
Logs are stored under /config (easy to put into a seperate external dataset and with room for future config files)

How to?
Create both files in a directory and run ./kms.sh, be happy about it.

./kms.sh

echo '{"pkgs":["bash","ca_root_nss","nano","py37-tkinter","py37-pip","py37-sqlite3","git"]}' > /tmp/pkg.json
iocage create -n "kms" -p /tmp/pkg.json -r 11.3-RELEASE dhcp=on" allow_raw_sockets="1" boot="on"
rm /tmp/pkg.json
iocage exec kms mkdir -p /config
iocage exec kms svn checkout https://github.com/SystemRage/py-kms/trunk/py-kms /usr/local/share/py-kms
iocage exec kms "pw user add kms -c kms -u 666 -d /nonexistent -s /usr/bin/nologin"
iocage exec kms chown -R kms:kms /usr/local/share/py-kms /config
iocage exec kms mkdir /usr/local/etc/rc.d
cp ./py_kms /mnt/tank/iocage/jails/kms/root/usr/local/etc/rc.d/py_kms
iocage exec kms chmod u+x /usr/local/etc/rc.d/py_kms
iocage exec kms sysrc "py_kms_enable=YES"
iocage exec kms service py_kms start

./py_kms

#!/bin/sh

# $FreeBSD$
#
# PROVIDE: py_kms
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# py-kms_enable: Set to YES to enable py-kms
# Default: NO
# py-kms_user: The user account used to run the py-kms daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run as root.
# Default: media
# py-kms_group: The group account used to run the py-kms daemon.
# This is optional, however do not specifically set this to an
# empty string as this will cause the daemon to run with group wheel.
# Default: media
# py-kms_data_dir: Directory where py-kms configuration
# data is stored.

. /etc/rc.subr
name=py_kms
rcvar=${name}_enable
load_rc_config $name

: ${py_kms_enable:="NO"}
: ${py_kms_user:="kms"}
: ${py_kms_group:="kms"}
: ${py_kms_data_dir:="/config"}

command="/usr/local/bin/python3.7"
command_args="/usr/local/share/py-kms/pykms_Server.py 0.0.0.0 1688 -F ${py_kms_data_dir}/py-kms.log etrigan start --etrigan-pid ${py_kms_data_dir}/etrigan.pid"

run_rc_command "$1"

Hereby both files are co-licenced "Unlicence", so Maintainers are free to do with this as they please! :)
I suggest a Wiki article, Freenas plugin creation or including the code.
In any case it has now been documented here for future interested parties!

default address should not be 0.0.0.0 for IPV6

You add ipv6 support but doesn't change the default ip address configuration in pykms_Server.py.
Also the wiki must be modified too!!
Or it will throw a error message:
"Connection failed '0.0.0.0:1688': [Errno -9] Address family for hostname not supported!"
I have this problem when I use your code on debian 10 platform.
Please modify the default ip address to ipv6 format.

Run py-kms as windows 2008R2 service

Download and install:
https://www.python.org/ftp/python/2.7.14/python-2.7.14.amd64.msi (into C:\Windows\Python27)
https://github.com/mhammond/pywin32/releases/download/b222/pywin32-222.win-amd64-py2.7.exe

Download and extract py-kms-master.zip into C:\Windows\Python27\py-kms
cd C:\Windows\Python27\py-kms\

Create file kms-winservice.py and put into file this code:

import win32serviceutil
import win32service
import win32event
import servicemanager
import socket
import subprocess

class AppServerSvc (win32serviceutil.ServiceFramework):
    _svc_name_ = "py-kms"
    _svc_display_name_ = "py-kms"
    _proc = None
    _cmd = ["C:\Windows\Python27\python.exe", "C:\Windows\Python27\py-kms\server.py"]

    def __init__(self,args):
        win32serviceutil.ServiceFramework.__init__(self,args)
        self.hWaitStop = win32event.CreateEvent(None,0,0,None)
        socket.setdefaulttimeout(60)

    def SvcStop(self):
        self.killproc()
        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)
        win32event.SetEvent(self.hWaitStop)

    def SvcDoRun(self):
        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE,
                              servicemanager.PYS_SERVICE_STARTED,
                              (self._svc_name_,''))
        self.main()

    def main(self):
        self._proc = subprocess.Popen(self._cmd)
        self._proc.wait()

    def killproc(self):
        self._proc.kill()

if __name__ == '__main__':
    win32serviceutil.HandleCommandLine(AppServerSvc)

C:\Windows\Python27\python.exe kms-winservice.py install
services.msc

Find "py-kms" service and change startup type from manual to auto.
Try to start the py-kms service.
Try activate Windows Server 2008 R2 VL:
slmgr.vbs /skms 127.0.0.1
slmgr.vbs /ato

error when running under systemd

When trying to run under Systemd i'm getting the following error

May 21 23:07:24 rpi3 systemd[1]: Started PY-KMS Service. May 21 23:07:26 rpi3 python3[8791]: Traceback (most recent call last): May 21 23:07:26 rpi3 python3[8791]: File "/opt/py-kms/py-kms/pykms_Server.py", line 266, in <module> May 21 23:07:26 rpi3 python3[8791]: srv_main_with_gui() May 21 23:07:26 rpi3 python3[8791]: File "/opt/py-kms/py-kms/pykms_Server.py", line 197, in srv_main_with_gui May 21 23:07:26 rpi3 python3[8791]: root = pykms_GuiBase.KmsGui() May 21 23:07:26 rpi3 python3[8791]: File "/opt/py-kms/py-kms/pykms_GuiBase.py", line 77, in __init__ May 21 23:07:26 rpi3 python3[8791]: tk.Tk.__init__(self, *args, **kwargs) May 21 23:07:26 rpi3 python3[8791]: File "/usr/lib/python3.5/tkinter/__init__.py", line 1880, in __init__ May 21 23:07:26 rpi3 python3[8791]: self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) May 21 23:07:26 rpi3 python3[8791]: _tkinter.TclError: no display name and no $DISPLAY environment variable May 21 23:07:26 rpi3 systemd[1]: py-kms.service: Main process exited, code=exited, status=1/FAILURE

Abuse notice

That's not a real issue, i just want to tell you that microsoft seems to scan ip adresses for KMS servers. I received a copyright abuse yesterday... btw i changed default port to a custom one :(

[PROPOSAL] Make docker integration better

I would like to see a better integration into docker. @SystemRage What do you think about following changes:

  • Create an "official" py-kms image at the docker hub (in that case it would be good when the projects owner creates an account and sets it up to auto-build the master using the docker hub infrastructure)
  • Update the README to mention the new docker hub image
  • Add the new run command into the wiki (so it would use the official docker image from the hub)
  • Add a little tutorial for the docker build process to the wiki
  • Maybe reference a project like Watchtower for docker to ensure that the py-kms image is always up to date
    If @SystemRage approves this, I would happy to create the necessary merge requests and help at the realisation.

unpack requires a string argument of length 1

python pykms_Client.py

                        Client generating RPC Bind Request...

Server receiving
<===============        Client sending RPC Bind Request...



Server sending
===============>        Client received RPC Bind Response !!!

                        RPC Bind acknowledged !!!


                        Client generating Activation Request dictionary...

                        Client generating Activation Request data...

                        Client generating RPC Activation Request...

Server receiving
<===============        Client sending RPC Activation Request...





Server sending
===============>        Client received Response !!!

Traceback (most recent call last):
  File "pykms_Client.py", line 266, in <module>
    clt_main(with_gui = False)
  File "pykms_Client.py", line 188, in clt_main
    client_create()
  File "pykms_Client.py", line 151, in client_create
    parsed = MSRPCRespHeader(response)
  File "/opt/py-kms/pykms_Dcerpc.py", line 641, in __init__
    MSRPCHeader.__init__(self, aBuffer, alignment)
  File "/opt/py-kms/pykms_Dcerpc.py", line 588, in __init__
    Structure.__init__(self,data, alignment)
  File "/opt/py-kms/pykms_Structure.py", line 110, in __init__
    self.fromString(data)
  File "/opt/py-kms/pykms_Structure.py", line 167, in fromString
    self[field[0]] = self.unpack(field[1], data[:size], dataClassOrCode = dataClassOrCode, field = field[0])
  File "/opt/py-kms/pykms_Structure.py", line 329, in unpack
    return self.unpack(two[0],data)
  File "/opt/py-kms/pykms_Structure.py", line 385, in unpack
    return unpack(format, b(data))[0]
struct.error: ('unpack requires a string argument of length 1', "When unpacking field 'ver_major | B=5 | ''[:1]'")

Do yourself a favor and:

  • Document breaking changes such as -v to -V and -f to -F.
  • Learn how to use Git instead of generating 40 useless commits and uploading local changes with literally no history of what happened
  • Test your stuff
  • Use GitHub releases for keeping archived versions of old releases - it will do so automatically when you create tag with release version. Git is not for storing backup files.
  • Decide whether you want to use Python 3 or Python 2 in README examples - example command for Ubuntu installs both versions but then installs and uses pip for Python 2 only.

Office 2019!

Hello, first many thanks for the port it works flawlessly!

Is there any place where one might find the UUIDs required to make with work with Office 2019?

Thank you.

Auto start py-KMS as a background process in Arch based distro (Manjaro)

Hey many thanks for the Py-KMS. It's working out of the box. I'm running a Arch based Linux distro (Manjaro) that is using systemd. When I try to run sudo nano /etc/init/py-kms.conf it'll not update the entry, as

/etc/init/

doesn't exist in Manjaro or Arch based distro it has

/etc/init.d/

Can you please help me regarding how to manage a daemon that runs as a background process for py-kms in Arch based distro?

High CPU load on RPI 4b

I installed py-kms on a RPI 4b with 4GB of RAM and I noticed it takes 100% CPU (1 core out of 4).

top - 19:59:08 up 1 day, 17:34,  1 user,  load average: 0.81, 0.64, 0.82
Tasks: 127 total,   1 running, 126 sleeping,   0 stopped,   0 zombie
%Cpu(s): 25.1 us,  0.0 sy,  0.0 ni, 74.9 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :   3955.6 total,   2359.3 free,    775.7 used,    820.5 buff/cache
MiB Swap:      0.0 total,      0.0 free,      0.0 used.   3166.2 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU  %MEM     TIME+ COMMAND
30230 nobody    20   0   49128  16620   9716 S 100.0   0.4   0:30.74 python3
11548 openhab   20   0  610984 370832  15064 S   0.3   9.2   5:33.54 java
30235 openhab+  20   0   10668   3052   2608 R   0.3   0.1   0:00.10 top
    1 root      20   0   33844   8288   6440 S   0.0   0.2   0:31.54 systemd
    2 root      20   0       0      0      0 S   0.0   0.0   0:00.08 kthreadd
    3 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_gp
    4 root       0 -20       0      0      0 I   0.0   0.0   0:00.00 rcu_par_gp
  Load average: 1.00 1.06 1.06                                                                                        Tasks: 45, 243 thr; 2 running
  1  [||                                                                                                      1.1%]   Uptime: 1 day, 17:55:22
  2  [|||||||                                                                                                 5.1%]
  3  [||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||100.0%]
  4  [|                                                                                                       0.5%]
  Mem[|||||||||||||||||||||||||||||||||||||||||||||||                                                   787M/3.86G]
  Swp[                                                                                                       0K/0K]

  PID USER      PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command
30236 nobody     20   0 49128 16620  9716 R 99.5  0.4 21:07.36 /usr/bin/python3 /opt/py-kms/py-kms/pykms_Server.py --logfile /var/log/pykms_logserver.log
30230 nobody     20   0 49128 16620  9716 S 99.5  0.4 21:08.04 /usr/bin/python3 /opt/py-kms/py-kms/pykms_Server.py --logfile /var/log/pykms_logserver.log
11548 openhab    20   0  596M  362M 15064 S  0.5  9.2  5:56.23 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.log
  848 openhabia  20   0  9656  3880  2328 R  3.1  0.1  0:00.24 htop
11434 influxdb   20   0  964M  177M 29912 S  0.5  4.5 10:38.58 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
  307 avahi      20   0  5904  2524  2272 S  0.0  0.1  0:59.65 avahi-daemon: running [pi4.local]
11445 influxdb   20   0  964M  177M 29912 S  0.0  4.5  1:05.61 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
11469 influxdb   20   0  964M  177M 29912 S  0.0  4.5  0:50.28 /usr/bin/influxd -config /etc/influxdb/influxdb.conf
11704 openhab    20   0  596M  362M 15064 S  0.0  9.2  0:07.26 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.log
11738 openhab    20   0  596M  362M 15064 S  0.0  9.2  0:15.82 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.log
11760 openhab    20   0  596M  362M 15064 S  0.0  9.2  0:13.83 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.log
11958 openhab    20   0  596M  362M 15064 S  0.0  9.2  0:15.54 /usr/bin/java -Dopenhab.home=/usr/share/openhab2 -Dopenhab.conf=/etc/openhab2 -Dopenhab.runtime=/usr/share/openhab2/runtime -Dopenhab.userdata=/var/lib/openhab2 -Dopenhab.log
openhabian@pi4:/opt/py-kms/py-kms $ uname -a
Linux pi4 4.19.97-v7l+ #1294 SMP Thu Jan 30 13:21:14 GMT 2020 armv7l GNU/Linux

The log file is empty (size zero).

Is there any way to solve this?

Thanks
Cristian

Remove official support for Python 2

at least for the Docker images.

Python 2 is (the last time I checked) EOL and therefore considered a security risk.

I'll start to implement a PR for that in the next days

py-kms as a daemon for ubuntu 14.04LTS

nano /etc/init/py-kms.conf

description "py-kms"
author  "myanaloglife"
env PYTHON_HOME=/<dir>
env PATH=$PYTHON_HOME:$PATH
start on runlevel [2345]
stop on runlevel [016]
chdir <path to py-kms>
exec $PYTHON_HOME/bin/python server.py <server address> <server port> -v DEBUG --logfile /var/log/py-kms_server.log
respawn

initctl reload-configuration
start py-kms

py-kms on W2012R2 as service start and then stop

Hello
Installed py-kmc as written on the wiki (#2). Copied pywintypes38.dll to the Win32 folder #47. python-3.8.3-amd64 and pywin32-228.win-amd64-py3.8 also installed. Service py-kms installed successeful but it run and stop (((. What am I doing wrong? No errors in Windows Event and Path to Executable in service py-kmc is "C:\Python38\lib\site-packages\win32\PythonService.exe"

--hwid fails when the HWID begins or ends with 0

For example:

python pykms_Server.py 0.0.0.0 1688 --logfile STDOUT --hwid 7519597CB34CD5C0
Sun, 02 Feb 2020 06:50:37 ERROR    HWID '7519597CB34CD5C' is invalid. Hex string is odd length. Exiting...
python pykms_Server.py 0.0.0.0 1688 --logfile STDOUT --hwid 0000000000000000
Sun, 02 Feb 2020 06:53:47 ERROR    HWID '' is invalid. Hex string is too short. Exiting...
python pykms_Server.py 0.0.0.0 1688 --logfile STDOUT --hwid 0000000000000001
Sun, 02 Feb 2020 06:55:26 ERROR    HWID '1' is invalid. Hex string is odd length. Exiting...

Log to STDOUT

Hi there,

Firstly I want to thank you for this diagnostic tool. We are using it to test the user experience of upgrading a few clients to KMS-based activations in our test lab before contacting MS and going through the hoops.

It would be great if you could log requests/results to STDOUT so that the docker container (supermarcus/pykms-docker is the one I'm using) can accurately log information? Simple log format of [time] - [ip / hostname] - [status of requested/activated] - [product (if available)] would be ideal!

I am checkpointing the VMs before and after the activation process, but it would be nice to just see which IPs are requesting / activating so I can go through and deactivate these quickly.

pykms defaults to logging to a path relative to the installed libraries

When installing pykms via regular distribution packaging (and not via pip as a regular user, or just running from a git checkout) the location pykms is installed to often is read-only for the user running pykms.

Yet, pykms defaults to logging to

os.path.dirname(os.path.abspath( __file__ )) + "/pykms_logserver.log"

Could this default be changed to be relative to the working directory, or could you just default to log to stdout?

This seems to be quite common for all docker-based installations, and installations using the system journal as well.

kmsbase keeps only one ApplicationID

First, I'd like to thank you very much.
I'd like to suggest you to make a tiny modification on kmsBase.py to allow KMSServer keeping all kms requests of different software instead only the last one.
I modified line 196 to:
cur.execute("SELECT * FROM clients WHERE clientMachineId=:clientMachineId AND applicationId=:appId;", infoDict)
I hope it helps.

Client error with python 2.7.15

			Client generating RPC Bind Request...,
,
,
								Client sending,
Server received RPC Bind Request !!!				<===============,
 * Running on http://0.0.0.0:8080/ (Press CTRL+C to quit),
No handlers could be found for logger "root",
Traceback (most recent call last):,
  File "/usr/lib/python2.7/SocketServer.py", line 290, in _handle_request_noblock,
    self.process_request(request, client_address),
  File "/usr/lib/python2.7/SocketServer.py", line 318, in process_request,
    self.finish_request(request, client_address),
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request,
    self.RequestHandlerClass(request, client_address, self),
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__,
    self.handle(),
  File "pykms_Server.py", line 242, in handle,
    res = enco(str(handler.populate()), 'latin-1'),
  File "/home/py-kms/pykms_RpcBase.py", line 42, in populate,
    return self.generateResponse(self.parseRequest()),
  File "/home/py-kms/pykms_RpcRequest.py", line 26, in generateResponse,
    responseData = pykms_Base.generateKmsResponseData(request['pduData'], self.srv_config),
  File "/home/py-kms/pykms_Base.py", line 257, in generateKmsResponseData,
    return messagehandler.executeRequestLogic(),
  File "/home/py-kms/pykms_RequestV5.py", line 75, in executeRequestLogic,
    responseBuffer = self.serverLogic(decrypted['request']),
  File "/home/py-kms/pykms_Base.py", line 208, in serverLogic,
    sql_update(self.dbName, infoDict),
  File "/home/py-kms/pykms_Sql.py", line 68, in sql_update,
    sys.exit(1),
NameError: global name 'sys' is not defined,
,
Server receiving,
<===============	Client sending RPC Bind Request...,
,
,
,
Server sending,
===============>	Client received RPC Bind Response !!!,
,
			RPC Bind acknowledged !!!,
,
,
			Client generating Activation Request dictionary...,
,
			Client generating Activation Request data...,
,
			Client generating RPC Activation Request...,
,
Server receiving,
<===============	Client sending RPC Activation Request...,
,
,
,
,
,
Server sending,
===============>	Client received Response !!!,
,
Traceback (most recent call last):,
  File "pykms_Client.py", line 268, in <module>,
    clt_main(with_gui = False),
  File "pykms_Client.py", line 190, in clt_main,
    client_create(),
  File "pykms_Client.py", line 151, in client_create,
    parsed = MSRPCRespHeader(response),
  File "/home/py-kms/pykms_Dcerpc.py", line 641, in __init__,
    MSRPCHeader.__init__(self, aBuffer, alignment),
  File "/home/py-kms/pykms_Dcerpc.py", line 588, in __init__,
    Structure.__init__(self,data, alignment),
  File "/home/py-kms/pykms_Structure.py", line 110, in __init__,
    self.fromString(data),
  File "/home/py-kms/pykms_Structure.py", line 167, in fromString,
    self[field[0]] = self.unpack(field[1], data[:size], dataClassOrCode = dataClassOrCode, field = field[0]),
  File "/home/py-kms/pykms_Structure.py", line 329, in unpack,
    return self.unpack(two[0],data),
  File "/home/py-kms/pykms_Structure.py", line 385, in unpack,
    return unpack(format, b(data))[0],
struct.error: ('unpack requires a string argument of length 1', "When unpacking field 'ver_major | B=5 | ''[:1]'"),

How can I fix this?

0xC004F069: Windows Server Eval error changing product key

When you try to set the product key on windows server Eval copies (180 evaluation timer), you sometimes get the following error:
Error: 0xC004F069 On a computer running Microsoft Windows non-core edition, run ‘slui.exe 0x2a 0xC004F069’ to display the error text

Tot fix this one can execute the following commands:

  1. Show the current version and versions that are compatible (optional):
    DISM.exe /Online /Get-TargetEditions

  2. Set the product to the VLK non-eval copy (Change the X's with your VLK key):
    DISM /online /Set-Edition:ServerStandard /ProductKey:XXXXX-XXXXX-XXXXX-XXXXX-XXXXX /AcceptEula

You might want to add this to the documentation.... ;)

-w option: invalid cases bypassed

using for example with -w ATYZD

Wed, 03 Jul 2019 22:29:26 ERROR HWID "AD" is invalid. Hex string is too short.
Wed, 03 Jul 2019 22:29:26 INFO     TCP server listening at 0.0.0.0 on port 1688.
Wed, 03 Jul 2019 22:29:26 INFO     HWID: AD
Wed, 03 Jul 2019 22:30:09 INFO     Connection accepted: 127.0.0.1:55218
# Sanitize HWID.
        try:
                srv_config['hwid'] = binascii.a2b_hex(re.sub(r'[^0-9a-fA-F]', '', srv_config['hwid'].strip('0x')))
                if len(binascii.b2a_hex(srv_config['hwid'])) < 16:
                        loggersrv.error("HWID \"%s\" is invalid. Hex string is too short." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                        return
                elif len(binascii.b2a_hex(srv_config['hwid'])) > 16:
                        loggersrv.error("HWID \"%s\" is invalid. Hex string is too long." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                        return
        except TypeError:
                loggersrv.error("HWID \"%s\" is invalid. Odd-length hex string." % deco(binascii.b2a_hex(srv_config['hwid']), 'utf-8').upper())
                return

Not return but sys.exit(). Then need optimization error cases (even short, even long, odd) and add another error when user input not hex chars (see re.sub()).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.