0%

搭建 KMS 服务

KMS Server

看到很多OpenWRT路由器中内置了kms服务插件,这样局域网内的office或Windows可以自动进行激活,十分方便。

背景

在每台 Windows 上安装激活工具,麻烦不说,还不安全。现在的激活工具太乱了。还是自建一台 KMS 激活服务器方便。

目前常用的 KMS 激活服务器程序为 Python 语言版本的 py-kms 与 C 语言版本的 vlmcsd。可在各种系统中运行,如OpenwRT/Android/Linux/Mac OS/iOS/Windows

下载地址:

  • Github-VLMCSD
  • Github-PyKMS

这里,我们在 Docker 中使用 py-kms

安装

  1. 安装 Docker-CE
  2. 下载 py-kms
    1
    :~$ git clone https://github.com/SystemRage/py-kms.git
  3. 国外用户,可以直接 py-kms 所提供的 Dockerfile 进行编译。但国内因国情的原因,编译时软件下载时间过长且还经常出现无法下载的错误提示。
    所以这里我修改了下 py-kms/docker/docker-py3-kms-minimal/Dockerfile,使用「清华源」来提升软件的下载速度。
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    # This is a minimized version from docker/docker-py3-kms/Dockerfile without SQLLite support to further reduce image size
    # https://raw.githubusercontent.com/SystemRage/py-kms/master/docker/docker-py3-kms-minimal/Dockerfile

    FROM alpine:latest

    ENV IP 0.0.0.0
    ENV PORT 1688
    #ENV EPID ""
    ENV LCID 1033
    ENV CLIENT_COUNT 26
    ENV ACTIVATION_INTERVAL 120
    ENV RENEWAL_INTERVAL 10080
    ENV HWID "RANDOM"
    ENV LOGLEVEL INFO
    ENV LOGFILE /var/log/pykms_logserver.log
    #ENV LOGSIZE ""

    EXPOSE ${PORT}/tcp

    RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apk/repositories \
    && apk add --no-cache --update bash git py3-argparse py3-flask py3-pygments python3-tkinter \
    sqlite-libs py3-pip p7zip \
    && pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple peewee tzlocal \
    && wget --no-check-certificate https://github.com/SystemRage/py-kms/archive/master.zip \
    && 7z x master.zip -o/home/ \
    && mv /home/py-kms-master/py-kms /home/ \
    && rm master.zip && rm -r /home/py-kms-master \
    && apk del git p7zip

    WORKDIR /home/py-kms

    ENTRYPOINT /usr/bin/python3 pykms_Server.py ${IP} ${PORT} -l ${LCID} -c ${CLIENT_COUNT} -a ${ACTIVATION_INTERVAL} -r ${RENEWAL_INTERVAL} -w ${HWID} -V ${LOGLEVEL} -F ${LOGFILE}

    HEALTHCHECK CMD netstat -ln | grep ${PORT} || exit 1
  4. 编译 Docker 镜像
    1
    :~$ cd py-kms/docker/docker-py3-kms-minimal && docker build -t haven200/py-kms .
  5. 运行 py-kms
    1
    2
    3
    4
    5
    6
    :~$ docker run --detach --name "kms"  \
    --publish 192.168.1.2:1688:1688/tcp \
    --volume /etc/localtime:/etc/localtime:ro \
    --env ACTIVATION_INTERVAL=1440 \
    --env RENEWAL_INTERVAL=20160 \
    "haven200/py-kms"
    • --publish: 将端口TCP 1688 映射出去,192.168.1.2为本机 IP
    • --volume: 使用本机的时区
    • --env: 导入环境变量
  6. 查看运行情况
    1
    2
    3
    :~$ docker container ls
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    547e355e1b3a haven200/py-kms "/bin/sh -c '/usr/bi…" About an hour ago Up About an hour (healthy) 192.168.100.101:1688->1688/tcp kms
  7. 查看端口是否映射
    1
    2
    :~$ docker container port kms
    1688/tcp -> 192.168.1.2:1688

此时,我们的py-kms服务器已经成功运行了。

检测 py-kms 服务

使用py-kms提供的测试软件 pykms_Client.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
:~$ python3 py-kms/py-kms/pykms_Client.py -m Windows10 192.168.1.2
truetruetrueClient generating RPC Bind Request...
Server receiving
<=============== Client sending RPC Bind Request...

Server sending
===============> Client received RPC Bind Response !!!
truetruetrueRPC Bind acknowledged !!!
truetruetrueClient generating Activation Request dictionary...
truetruetrueClient generating Activation Request data...
truetruetrueClient generating RPC Activation Request...

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

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

truetruetrueActivation Done !!!
  • -m:模拟哪个版本的系统或office,这里我们模拟的 Windows10
  • ip:此处一定要使用 IP 地址,使用域名会出错。

最后提示 Activation Done,即激活成功,说明我们的py-kms服务器已经成功无误的运行了。

配置 DNS 实现 Windows 自动发现 kms服务器

通过配置 DNS服务器 的 SRV 参数 来实现局域网内主机自动发现 kms服务器。
这样任何安装了 VOL 版的 office 及 windows 电脑,连接到我们的局域网就会自动进行激活。

1
2
3
4
:~$ sudo cat >> /etc/dnsmasq.conf <<EOF
srv-host=_vlmcs._tcp.nas.net,kms.nas.net,1688,0,100
EOF
:~$ sudo systemctl restart dnsmasq
  • _vlmcs: kms 服务类型
  • _tcp: 以 tcp 方式提供
  • nas.net: kms 服务器的后缀域名
  • kms.nas.net: kms 服务器的完整域名,可通过它查询到 IP 地址
  • 1688: kms 服务器的端口
  • 0: 优先极
  • 100: 权重

测试 dnsmasq 是否设置成功

1
2
3
4
5
:~$ nslookup -type=srv _vlmcs._tcp.nas.net
Server: 192.168.1.1
Address: 192.168.1.1#53

_vlmcs._tcp.nas.net service = 0 100 1688 kms.nas.net.

激活 office

此处以 2013 为例。

  • 手动指定 kms服务器
    1
    2
    3
    4
    cd "%ProgramFiles%\MICROSOFT OFFICE\OFFICE15"
    cscript ospp.vbs /sethst:192.168.1.2
    cscript ospp.vbs /act
    cscript ospp.vbs /dstatus
  • 自动发现 kms服务器并激活
    1
    2
    3
    4
    CD "%ProgramFiles(x86)%\MICROSOFT OFFICE\OFFICE15"
    cscript ospp.vbs /remhst
    cscript ospp.vbs /act
    cscript ospp.vbs /dstatus

如果自带 Key 不可用,使用下面的命令修改

1
cscript ospp.vbs /inpkey:KBKQT-2NMXY-JJWGP-M62JB-92CD4

KMS Keys(VOL) for office

MS Office edition KMS Setup Key (GVLK keys)
Office 2019 Professional Plus NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP
Office 2019 Standard 6NWWJ-YQWMR-QKGCB-6TMB3-9D9HK
Office 2016 Professional Plus XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99
Office 2016 Standard JNRGM-WHDWX-FJJG3-K47QV-DRTFM
Office 2013 Professional Plus YC7DK-G2NP3-2QQC3-J6H88-GVGXT
Office 2013 Standard KBKQT-2NMXY-JJWGP-M62JB-92CD4
Office 2010 Professional Plus VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB
Office 2010 Standard V7QKV-4XVVR-XYV4D-F7DFM-8R6BM

Windows 激活

  1. 卸载原有的 key
    1
    slmgr -upk
  2. 添加 key,请选择对应版本的 VOL Key
    1
    slmgr -ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
  3. 更改 kms服务器,如果已在 dns服务器上配置了 kms服务,则忽略此步骤。
    1
    slmgr -skms kms.nas.net
  4. 进行激活
    1
    slmgr -ato
  5. 查看激活信息
    1
    slmgr -xpr

常用的 VOL KEY

  • 旗舰版:是指功能完整的版本。
  • VOL版:指大客户批量授权版。

Windows 7 旗舰版 无法通过 KMS 激活,请使用其它工具激活。

Windows Server 2019

System Key
Windows Server 2019 Datacenter WMDGN-G9PQG-XVVXX-R3X43-63DFG
Windows Server 2019 Standard N69G4-B89J2-4G8F4-WWYCC-J464C
Windows Server 2019 Essentials WVDHN-86M7X-466P6-VHXV7-YY726

Windows 10

System Key
Windows 10 Enterprise LTSC 2019 M7XTQ-FN8P6-TTKYV-9D4CC-J462D
Windows 10 Enterprise N LTSC 2019 92NFX-8DJQP-P6BBQ-THF9C-7CG2H
Windows 10 Professional W269N-WFGWX-YVC9B-4J6C9-T83GX
Windows 10 Professional N MH37W-N47XK-V7XM9-C7227-GCQG9
Windows 10 Enterprise NPPR9-FWDCX-D2C8J-H872K-2YT43
Windows 10 Enterprise N DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4
Windows 10 Education NW6C2-QMPVW-D7KKK-3GKT6-VCFB2
Windows 10 Education N 2WH4N-8QGBV-H22JP-CT43Q-MDWWJ
Windows 10 Enterprise 2015 LTSB WNMTR-4C88C-JK8YV-HQ7T2-76DF9
Windows 10 Enterprise 2015 LTSB N 2F77B-TNFGY-69QQF-B8YKP-D69TJ
Windows 10 Enterprise 2016 LTSB DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJ
Windows 10 Enterprise 2016 LTSB N QFFDN-GRT3P-VKWWX-X7T3R-8B639

Windows Server 2016

System Key
Windows Server 2016 Datacenter CB7KF-BWN84-R7R2Y-793K2-8XDDG
Windows Server 2016 Standard WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY
Windows Server 2016 Essentials JCKRF-N37P4-C2D82-9YXRT-4M63B

Windows Server 2012 R2

System Key
Windows Server 2012 R2 Standard D2N9P-3P6X9-2R39C-7RTCD-MDVJX
Windows Server 2012 R2 Datacenter W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9
Windows Server 2012 R2 Essentials KNC87-3J2TX-XB4WP-VCPJV-M4FWM
Windows Server 2012 Core BN3D2-R7TKB-3YPBD-8DRP2-27GG4
Windows Server 2012 Core N 8N2M2-HWPGY-7PGT9-HGDD8-GVGGY
Windows Server 2012 Core Single Language 2WN2H-YGCQR-KFX6K-CD6TF-84YXQ
Windows Server 2012 Core Country Specific 4K36P-JN4VD-GDC6V-KDT89-DYFKP
Windows Server 2012 Server Standard XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 Standard Core XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 MultiPoint Standard HM7DN-YVMH3-46JC3-XYTG7-CYQJJ
Windows Server 2012 MultiPoint Premium XNH6W-2V9GX-RGJ4K-Y8X6F-QGJ2G
Windows Server 2012 Datacenter 48HP8-DN98B-MYWDG-T2DCC-8W83P
Windows Server 2012 Datacenter Core 48HP8-DN98B-MYWDG-T2DCC-8W83P

Windows 8.1

System Key
Windows 8.1 Professional GCRJD-8NW9H-F2CDX-CCM8D-9D6T9
Windows 8.1 Professional N HMCNV-VVBFX-7HMBH-CTY9B-B4FXY
Windows 8.1 Enterprise MHF9N-XY6XB-WVXMC-BTDCT-MKKG7
Windows 8.1 Enterprise N TT4HM-HN7YT-62K67-RGRQJ-JFFXW

Windows 8

System Key
Windows 8 Professional NG4HW-VH26C-733KW-K6F98-J8CK4
Windows 8 Professional N XCVCF-2NXM9-723PB-MHCB7-2RYQQ
Windows 8 Enterprise 32JNW-9KQ84-P47T8-D8GGY-CWCK7
Windows 8 Enterprise N JMNMF-RHW7P-DMY6X-RF3DR-X2BQT

Windows Server 2008 R2

System Key
Windows Server 2008 R2 HPC Edition FKJQ8-TMCVP-FRMR7-4WR42-3JCD7
Windows Server 2008 R2 Datacenter 74YFP-3QFB3-KQT8W-PMXWJ-7M648
Windows Server 2008 R2 Enterprise 489J6-VHDMP-X63PK-3K798-CPX3Y
Windows Server 2008 R2 for Itanium-Based Systems GT63C-RJFQ3-4GMB6-BRFB9-CB83V
Windows Server 2008 R2 Standard YC6KT-GKW9T-YTKYR-T4X34-R7VHC
Windows Web Server 2008 R2 6TPJF-RBVHG-WBW2R-86QPH-6RTM4
Windows Server 2008 Datacenter 7M67G-PC374-GR742-YH8V4-TCBY3
Windows Server 2008 Datacenter without Hyper-V 22XQ2-VRXRG-P8D42-K34TD-G3QQC
Windows Server 2008 for Itanium-Based Systems 4DWFP-JF3DJ-B7DTH-78FJB-PDRHK
Windows Server 2008 Enterprise YQGMW-MPWTJ-34KDK-48M3W-X4Q6V
Windows Server 2008 Enterprise without Hyper-V 39BXF-X8Q23-P2WWT-38T2F-G3FPG
Windows Server 2008 Standard TM24T-X9RMF-VWXK6-X8JC9-BFGM2
Windows Server 2008 Standard without Hyper-V W7VD6-7JFBR-RX26B-YKQ3Y-6FFFJ
Windows Web Server 2008 WYR28-R7TFJ-3X2YQ-YCY4H-M249D

Windows 7

System Key
Windows 7 Professional FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4
Windows 7 Professional N MRPKT-YTG23-K7D7T-X2JMM-QY7MG
Windows 7 Enterprise 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH
Windows 7 Enterprise N YDRBP-3D83W-TY26F-D46B2-XCKRJ
Windows 7 Enterprise E C29WB-22CC8-VJ326-GHFJW-H9DH4

Windows Vista

System Key
Windows Vista Business YFKBB-PQJJV-G996G-VWGXY-2V3X8
Windows Vista Business N HMBQG-8H2RH-C77VX-27R82-VMQBT
Windows Vista Enterprise VKK3X-68KWM-X2YGT-QR4M6-4BWMV
Windows Vista Enterprise N VTC42-BM838-43QHV-84HX6-XJXKV

References:

  • bitspace
  • pykms
  • vlmcsd
  • zvv
  • theitbros
---- The End Thanks ----
Donate if you like the article.