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
|