Chinaunix首页 | 论坛 | 博客
  • 博客访问: 16552
  • 博文数量: 7
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 45
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-10 09:44
文章分类

全部博文(7)

文章存档

2016年(1)

2013年(2)

2012年(2)

2011年(1)

2008年(1)

我的朋友
最近访客

分类: LINUX

2013-03-02 22:25:59

原文地址:获取本机硬件码 作者:静飞lv

将本机硬件信息(CPU、主板、内存、硬盘、网卡)写入文件,求出该文件MD5值,即为该机器的硬件码

我的源码如下:


#!/bin/bash
###########################
#功能:获取硬件码
#作者:
#日期:
###########################
dmidecode="/usr/sbin/dmidecode"
smartctl="/usr/sbin/smartctl"
df="/bin/df"
lspci="/sbin/lspci"
eth_file="/etc/udev/rules.d/70-persistent-net.rules"

if [ ! -f $dmidecode ]
then
	echo "dmidecode: command not found!"
	echo "please \"yum\" to install it"
	exit
fi

path=`pwd`
tmp_file=$path"/hdid_tmp"
touch $tmp_file
> $tmp_file

#获取cpu信息
echo "CPU information:" >> $tmp_file
$dmidecode -t processor | awk '/ID|Version|Serial Number|Core Count/'| sed 's/^[ \t]*//g' >> $tmp_file

#获取BIOS信息
echo -e "\nBIOS information:" >> $tmp_file
$dmidecode -t bios | awk '/Vendor/,/Release Date/'| sed 's/^[ \t]*//g' >> $tmp_file

#获取内存信息
echo -e "\nMemory information:" >> $tmp_file
$dmidecode -t memory | awk '/Number Of Devices|^[ \t]*Size|Locator|Serial Number|Part Number/' | sed 's/^[ \t]*//g' >> $tmp_file

#获取硬盘信息
echo -e "\nDisk information:" >> $tmp_file
dev_name=`$df | grep dev | head -n 1 | awk '{print $1}'`
$smartctl -a $dev_name | awk '/Device Model/,/Firmware Version/' >> $tmp_file

#获取网卡信息
echo -e "\nEthernet information:" >> $tmp_file
$lspci | grep "Ethernet controller" >> $tmp_file
while read line
do
        put_out=`echo $line | sed -r "s/(.*)address\}==\"([a-z0-9:]{17})\",(.*)NAME=\"(.*)\"/\2 \4/g"`
        mac=`echo $put_out | awk '{print $1}'`
        if [ ${#mac} -eq 17 ]
        then
                echo $put_out >> $tmp_file
        fi
done <$eth_file

#硬件信息文件MD5值为硬件信息码
/usr/bin/md5sum -t $tmp_file | awk '{print $1}'
rm -rf $tmp_file


阅读(324) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~