当前位置: 首页 > news >正文

【收集电脑信息】collect_info.sh

收集电脑信息

collect_info.sh

#!/bin/bashoutput="info.txt"
> "$output"# 1. OS Version
echo "=== 操作系统名称及版本 ===" >> "$output"
lsb_release -d | cut -f2- >> "$output"
echo -e "\n" >> "$output"# 2. Installation Time
echo "=== 系统安装时间 ===" >> "$output"
ROOT_DEVICE=$(df -h | grep "/dev/root" | awk '{print $1}')
if [ -z "$ROOT_DEVICE" ]; thenROOT_DEVICE=$(mount | grep " / " | awk '{print $1}')
fiif [ -n "$ROOT_DEVICE" ]; thenfs_create_time=$(sudo tune2fs -l "$ROOT_DEVICE" 2>/dev/null | grep "Filesystem created" | cut -d ':' -f2-)if [ -n "$fs_create_time" ]; thenecho "$fs_create_time" >> "$output"elseecho "无法获取系统安装时间(tune2fs 失败)" >> "$output"fi
elseecho "无法识别根分区设备" >> "$output"
fi
echo -e "\n" >> "$output"# 3. Disk Info
echo "=== 硬盘信息 ===" >> "$output"for disk in $(ls /dev/sd* | grep -v "[0-9]" 2>/dev/null); domodel=$(sudo hdparm -I "$disk" 2>/dev/null | grep "Model Number" | sed 's/.*: //; s/^[ \t]*//')serial=$(sudo hdparm -I "$disk" 2>/dev/null | grep "Serial Number" | sed 's/.*: //; s/^[ \t]*//')echo "设备: $disk" >> "$output"echo "型号: ${model:-N/A}" >> "$output"echo "序列号: ${serial:-N/A}" >> "$output"echo "-----------------------------" >> "$output"
doneif command -v nvme &> /dev/null; thenfor dev in $(nvme list | awk '/dev\/nvme/{print $1}' 2>/dev/null); dosn=$(sudo nvme id-ctrl "$dev" | grep -i "sn" | head -1 | awk '{print $3}' | tr -d '"')mn=$(sudo nvme id-ctrl "$dev" | grep -i "mn" | head -1 | awk '{print substr($0, index($0,$3))}' | tr -d '"')echo "设备: $dev" >> "$output"echo "型号: ${mn:-N/A}" >> "$output"echo "序列号: ${sn:-N/A}" >> "$output"echo "-----------------------------" >> "$output"done
elseecho "未安装 nvme-cli,请安装:sudo apt install nvme-cli" >> "$output"
fiif ! ls /dev/sd* > /dev/null 2>&1 && ! (command -v nvme &> /dev/null && nvme list > /dev/null 2>&1); thenecho "未检测到硬盘设备。" >> "$output"
fi
echo -e "\n" >> "$output"# 4. Network MAC Addresses
echo "=== 网卡 MAC 地址 ===" >> "$output"# === 网卡 MAC 地址 ===
echo "=== 网卡 MAC 地址 ===" >> "$output"eth_detected=0
wifi_detected=0ip link show | awk '
BEGIN {OFS=": "
}
$0 ~ /state UP/ {getlineif ($0 ~ /ether/) {mac = $2sub(/.*</, "", $1)sub(/>:.*/, "", $1)interface = $1# 根据接口名判断类型(简单规则)if (interface ~ /^en/) {print "有线网卡 ("interface"): "maceth_detected = 1} else if (interface ~ /^wl/) {print "无线网卡 ("interface"): "macwifi_detected = 1} else {print "未知网卡 ("interface"): "mac}}
}' >> "$output"# 提示未检测到的情况
if [[ "$eth_detected" -ne 1 ]]; thenecho "未检测到有线网卡。" >> "$output"
fiif [[ "$wifi_detected" -ne 1 ]]; thenecho "未检测到无线网卡。" >> "$output"
fi
http://www.dtcms.com/a/285616.html

相关文章:

  • 【NLP舆情分析】基于python微博舆情分析可视化系统(flask+pandas+echarts) 视频教程 - 基于jieba实现词频统计
  • Kubernetes Pod深度理解
  • 【数据可视化-67】基于pyecharts的航空安全深度剖析:坠毁航班数据集可视化分析
  • 【问题解决】npm包下载速度慢
  • 【AI大模型学习路线】第三阶段之RAG与LangChain——第十八章(基于RAGAS的RAG的评估)RAG中的评估思路?
  • 把握流程节点,明确信息传递
  • C专题5:函数进阶和递归
  • 最小生成树算法详解
  • 2025外卖江湖:巨头争霸,谁主沉浮?
  • 洞见AI时代数据底座的思考——YashanDB亮相2025可信数据库发展大会
  • NIO网络通信基础
  • AndroidX中ComponentActivity与原生 Activity 的区别
  • 关于字符编辑器vi、vim版本的安装过程及其常用命令:
  • 从抓包GitHub Copilot认证请求,认识OAuth 2.0技术
  • web3 区块链技术与用
  • 基于深度学习的语音识别:从音频信号到文本转录
  • 开源的大语言模型(LLM)应用开发平台Dify
  • 如何用Python并发下载?深入解析concurrent.futures 与期物机制
  • 服务攻防-Java组件安全FastJson高版本JNDI不出网C3P0编码绕WAF写入文件CI链
  • ARM64高速缓存,内存属性及MAIR配置
  • 预测导管原位癌浸润性复发的深度学习:利用组织病理学图像和临床特征
  • Nand2Tetris(计算机系统要素)学习笔记 Project 3
  • sqli(1-8)
  • ASP.NET Core Web API 内存缓存(IMemoryCache)入门指南
  • Pytorch下载Mnist手写数据识别训练数据集的代码详解
  • PyTorch新手实操 安装
  • 填坑 | React Context原理
  • SpringMVC + Tomcat10
  • 小结:Spring MVC 的 XML 的经典配置方式
  • 计算机视觉与机器视觉