From 6846a4c98a793e74ae17b47f04a0ff8b210aeb24 Mon Sep 17 00:00:00 2001 From: zhaoqingang <zhaoqg0118@163.com> Date: 星期二, 01 四月 2025 16:52:51 +0800 Subject: [PATCH] 授权license --- app/utils/common.py | 25 +++++++++++++++++++++++++ 1 files changed, 25 insertions(+), 0 deletions(-) diff --git a/app/utils/common.py b/app/utils/common.py index e3ac4a6..cacda03 100644 --- a/app/utils/common.py +++ b/app/utils/common.py @@ -1,6 +1,31 @@ import pytz +import platform +import subprocess + from datetime import datetime + def current_time(): tz = pytz.timezone('Asia/Shanghai') return datetime.now(tz) + + +def get_machine_id(): + """鑾峰彇鏈哄櫒鐨勫敮涓�鏍囪瘑""" + if platform.system() == "Windows": + # Windows 绯荤粺 + command = "wmic csproduct get UUID" + process = subprocess.Popen(command.split(), stdout=subprocess.PIPE) + output, _ = process.communicate() + machine_id = output.decode().strip().split("\n")[1].strip() + elif platform.system() == "Darwin": + # macOS 绯荤粺 + command = "system_profiler SPHardwareDataType | grep 'Hardware UUID' | awk '{print $4}'" + process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) + output, _ = process.communicate() + machine_id = output.decode().strip() + else: + # Linux 绯荤粺 + machine_id = open("/etc/machine-id").read().strip() + # print(machine_id) + return machine_id \ No newline at end of file -- Gitblit v1.8.0