本文目录导读:

- Windows (PowerShell)
- Linux/Unix (Bash)
- Python (跨平台)
- Windows Batch
- JavaScript (Node.js)
- AppleScript (macOS)
- 安装依赖
- 使用方法
Windows (PowerShell)
# 获取操作系统信息
Get-ComputerInfo | Select-Object WindowsVersion, WindowsBuildLabEx, OsArchitecture
# 获取CPU信息
Get-CimInstance Win32_Processor | Select-Object Name, NumberOfCores, MaxClockSpeed
# 获取内存信息
Get-CimInstance Win32_ComputerSystem | Select-Object TotalPhysicalMemory
Get-CimInstance Win32_OperatingSystem | Select-Object TotalVisibleMemorySize, FreePhysicalMemory
# 获取磁盘信息
Get-CimInstance Win32_LogicalDisk -Filter "DriveType=3" |
Select-Object DeviceID, Size, FreeSpace
# 获取网卡信息
Get-NetAdapter | Select-Object Name, Status, MacAddress, LinkSpeed
Linux/Unix (Bash)
#!/bin/bash
# 操作系统信息
echo "OS: $(uname -o)"
echo "Kernel: $(uname -r)"
echo "Architecture: $(uname -m)"
# CPU信息
echo "CPU: $(nproc) cores"
echo "CPU Model: $(lscpu | grep 'Model name' | cut -f 2 -d ':')"
# 内存信息
echo "Total RAM: $(free -h | grep Mem | awk '{print $2}')"
echo "Free RAM: $(free -h | grep Mem | awk '{print $4}')"
# 磁盘信息
df -h | grep '^/dev/' |
awk '{print $1, "Total:", $2, "Used:", $3, "Free:", $4}'
# 网络信息
ip addr show | grep 'inet ' | awk '{print $2, $NF}'
Python (跨平台)
import platform
import psutil
import socket
# 操作系统信息
print(f"System: {platform.system()}")
print(f"Release: {platform.release()}")
print(f"Version: {platform.version()}")
print(f"Machine: {platform.machine()}")
print(f"Processor: {platform.processor()}")
# CPU信息
print(f"CPU Cores: {psutil.cpu_count()}")
print(f"CPU Usage: {psutil.cpu_percent()}%")
# 内存信息
memory = psutil.virtual_memory()
print(f"Total RAM: {memory.total / (1024**3):.2f} GB")
print(f"Available RAM: {memory.available / (1024**3):.2f} GB")
# 磁盘信息
for disk in psutil.disk_partitions():
usage = psutil.disk_usage(disk.mountpoint)
print(f"{disk.device}: Total: {usage.total / (1024**3):.2f} GB, "
f"Free: {usage.free / (1024**3):.2f} GB")
# 网络信息
hostname = socket.gethostname()
ip_address = socket.gethostbyname(hostname)
print(f"Hostname: {hostname}")
print(f"IP Address: {ip_address}")
# 用户信息
import getpass
print(f"Current User: {getpass.getuser()}")
Windows Batch
@echo off echo === System Information === echo Operating System: wmic os get Caption, Version, BuildNumber echo CPU: wmic cpu get Name, NumberOfCores, MaxClockSpeed echo Memory: wmic memorychip get Capacity, Speed, MemoryType echo Disk: wmic logicaldisk where DriveType=3 get DeviceID, Size, FreeSpace echo Network: ipconfig | findstr /i "IPv4"
JavaScript (Node.js)
const os = require('os');
const fs = require('fs');
const { execSync } = require('child_process');
// 操作系统信息
console.log('Platform:', os.platform());
console.log('Release:', os.release());
console.log('Architecture:', os.arch());
console.log('Hostname:', os.hostname());
// CPU信息
console.log('CPU Cores:', os.cpus().length);
console.log('CPU Model:', os.cpus()[0].model);
// 内存信息
const totalMem = os.totalmem() / (1024 ** 3);
const freeMem = os.freemem() / (1024 ** 3);
console.log(`Total RAM: ${totalMem.toFixed(2)} GB`);
console.log(`Free RAM: ${freeMem.toFixed(2)} GB`);
// 磁盘信息(需要exec)
const diskInfo = execSync('df -h').toString();
console.log('Disk Info:', diskInfo);
// 网络接口
const networkInterfaces = os.networkInterfaces();
console.log('Network:', JSON.stringify(networkInterfaces, null, 2));
// 系统运行时间
console.log('Uptime:', os.uptime(), 'seconds');
AppleScript (macOS)
tell application "System Events"
set osVersion to system version
set computerName to computer's name
end tell
-- 获取更多系统信息
do shell script "system_profiler SPHardwareDataType" |>
set hardwareInfo to result
-- 获取内存信息
do shell script "vm_stat" |>
set memoryInfo to result
-- 获取磁盘信息
do shell script "df -h" |>
set diskInfo to result
安装依赖
Python
pip install psutil
Node.js
无需安装额外依赖(os是内置模块)
使用方法
- Windows: 保存为
.ps1文件,右键选择"用PowerShell运行" - Linux: 保存为
.sh文件,chmod +x script.sh && ./script.sh - Python:
python3 script.py - Node.js:
node script.js
选择最适合你平台的脚本即可!