def readfiletoexcel():
wb = xlwt.Workbook()
sheet = wb.add_sheet('端口信息')
#['Interface', 'PHY', 'Protocol', 'InUti', 'OutUti', 'inErrors', 'outErrors']
sheet.write(0,0,'Interface')
sheet.write(0,1,'PHY')
sheet.write(0,2,'Protocol')
sheet.write(0,3,'InUti')
sheet.write(0,4,'OutUti')
sheet.write(0,5,'inErrors')
sheet.write(0,6,'outErrors')
f = open("interface.txt", "r", encoding='utf-8')
lines = f.readlines()
result = "".join(lines)
res = result.split("\n")
j=0
for i in range(0,len(res)):
if len(re.findall(r'Interface',res[i]))>0:
j = i
regex = re.compile(r'GE.+\s+.+\s+.+\s+.+\s+.+\s+.+\s+.+',re.S)
if len(re.findall(regex, res[i])) > 0:
str = re.split('\s+',res[i])
print(str)
sheet.write(i-j,0,str[0])
sheet.write(i-j,1,str[1])
sheet.write(i-j,2,str[2])
sheet.write(i-j,3,str[3])
sheet.write(i-j,4,str[4])
sheet.write(i-j,5,str[5])
sheet.write(i-j,6,str[6])
wb.save("result.xls")
readfiletoexcel()
python往excel中写端口信息
Guaiacum_2024-10-12 23:13
相关推荐
高洁0112 分钟前
数字孪生与计算机视觉:让机器看懂现场ComPDFKit18 分钟前
RAG 回答只显示 PDF 文件名?用 Python 保留引用页码FRing0328 分钟前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)yz_aiks2 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)琳少_3 小时前
java程序开发笔记七夜zippoe3 小时前
Agent 告警设计:分级告警、智能降噪与值班排班2601_967980114 小时前
Flask Web 应用aifannihao4 小时前
ß 大写变 SS:用 Python 算清 Ruby2Shell 的缓冲区账本liwulin05064 小时前
【OLLAMA】调用SKILL的通用ReAct严肃小白兔5 小时前
PHP 8.6 正式发布:部分函数应用、原生 I/O 轮询与新特性实战解析