本文共 473 字,大约阅读时间需要 1 分钟。
需求: 1. 获取当前主机信息, 包含操作系统名, 主机名, 内核版本, 硬件架构等 2. 获取开机时间和开机时长; 3. 获取当前登陆用户
"""import osimport psutilfrom datetime import datetimeprint('主机信息'.center(50,'*'))info = os.uname()print(""" 操作系统:%s 主机名称:%s 内核版本:%s 硬件架构:%s"""%(info.sysname,info.nodename,info.release,info.machine))print('开机信息'.center(50,'*'))boot_time = psutil.boot_time() #返回的是一个时间戳# 将时间戳转化为datatime类型的时间boot_time_obj = datetime.fromtimestamp(boot_time)print(type(boot_time_obj))now_time = datetime.now()
转载地址:http://hqdwi.baihongyu.com/