代码拉取完成,页面将自动刷新
import os
import platform
import subprocess
with open('/etc/os-release') as f:
lines = f.readlines()
# 获取用户名和机器名
username = os.getenv('USER')
hostname = platform.node()
# 获取系统版本信息
#system_version = platform.platform()
os_name = None
for line in lines:
if line.startswith('NAME='):
os_name = line.split('=')[1].strip().replace('"', '')
break
# 获取机器型号
#machine_model = platform.machine()
machine_model = subprocess.check_output("cat /sys/class/dmi/id/product_name", shell=True).decode('utf-8').strip()
# 获取CPU信息
cpu_info = subprocess.check_output("cat /proc/cpuinfo | grep 'model name' | head -n 1 | awk -F: '{print $2}'", shell=True).decode('utf-8').strip()
# 获取GPU信息
gpu_info = subprocess.check_output("lspci | grep -i 'VGA\|3D\|2D'", shell=True).decode('utf-8').strip()
# 获取内存信息
memory_info = subprocess.check_output("free -h | awk 'NR==2{print $2}'", shell=True).decode('utf-8').strip()
# 获取内核版本
kernel_version = platform.uname().release
# 获取开机时间
uptime = subprocess.check_output("uptime -p", shell=True).decode('utf-8').strip()
# 获取包管理器
package_manager = ""
if os.path.exists('/usr/bin/apt'):
package_manager = "apt/apt-get"
elif os.path.exists('/usr/bin/dnf'):
package_manager = "dnf"
elif os.path.exists('/usr/bin/yum'):
package_manager = "yum"
elif os.path.exists('/usr/bin/zpm'):
package_manager = "zpm"
# 获取Shell
shell = os.getenv('SHELL')
# 获取当前时间
current_time = subprocess.check_output("date", shell=True).decode('utf-8').strip()
# 获取分辨率
resolution = subprocess.check_output("xrandr | grep '*' | awk '{print $1}'", shell=True).decode('utf-8').strip()
# 获取桌面环境
desktop_environment = os.getenv('XDG_CURRENT_DESKTOP')
# 获取窗口管理器
window_manager = os.getenv('XDG_SESSION_DESKTOP')
# 获取当前主题
theme = os.getenv('GTK_THEME')
# 获取图标主题
icon_theme = os.getenv('ICON_THEME')
# 获取终端
terminal = os.getenv('TERM')
# 获取终端字体
terminal_font = subprocess.check_output("fc-match :family", shell=True).decode('utf-8').strip()
# 获取地区
locale = subprocess.check_output('timedatectl show --property=Timezone --value', shell=True).decode('utf-8').strip()
# 输出系统信息
print(f"{username}@{hostname}\n"
f"---------------System Info--------------\n"
f"系统版本: {os_name}\n"
f"机器型号: {machine_model}\n"
f"CPU: {cpu_info}\n"
f"GPU: {gpu_info}\n"
f"内存: {memory_info}\n"
f"内核版本: {kernel_version}\n"
f"开机时间: {uptime}\n"
f"包管理器: {package_manager}\n"
f"Shell: {shell}\n"
f"当前时间: {current_time}\n"
f"分辨率: {resolution}\n"
f"桌面环境: {desktop_environment}\n"
f"窗口管理器: {window_manager}\n"
f"当前主题: {theme}\n"
f"图标主题: {icon_theme}\n"
f"终端: {terminal}\n"
f"终端字体: {terminal_font}\n"
f"地区: {locale}")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。