因为集团急需所有机器具体硬件信息,又没有做域控制器,只能按照AIDA64的和CPUZ出报告的方法,最后汇总报告;
首先给全公司发通知自己运行AIDA64,但是发现有问题,所以指定了AIDA64的报告模板,
还有2个问题:
- 发现一个问题就是TXT太大了会报错编码问题,但是只要文件够小什么编码都没问题,怪了。
- 还有就是循环中不能连续IF判断,必须重新FOR才能抓到关键信息,好在不考虑效率,但是还是很怪。
让大家把报告按照“部门-名称”命名汇总给我,运行一下程序就合成所需硬件台账了
先放一下代码,后面说明;
import os
path01=r'E:\需设备台账\收集'
path02=r'E:\需设备台账\收集追加'
#路径前面加r避免转义字符
fileLists= os.listdir(path02)
txts=[]
temp=""
for f in fileLists:
if os.path.splitext(f)[-1]=='.txt':
position= path02 +'\\'+f
#构造绝对路径,\\是转义字符\
#print(position)
#print(os.path.splitext(f)[0])
CurrentFile=open(position)
lines=CurrentFile.readlines()
#按行读文件
temp=f
for line in lines:
line=line.strip()
if "安装日期" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "DMI 系统版本" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "DMI 系统序列号" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "ATA设备信息" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "操作系统名称" in line:
l=line.replace(" ",'')
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "密钥" in line:
l=line.replace(" ",'')
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "主 IP" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for line in lines:
line=line.strip()
if "主 MAC" in line:
l=line.replace(" ","")
temp=temp+'|'+l
for x,line in enumerate(lines) :
line=line.strip()
if "ATA 设备信息" in line:
l=lines[x+2].replace(' ','')
l=l.replace('\n','')
temp=temp+'|'+l
print(temp)
CurrentFile.close()