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
相关推荐
必须会一定会11 小时前
Agent Plugins 1.0实战:plugin.json、skills、mcp.json目录结构与迁移St_rive12 小时前
Page Object设计模式CTA量化套保12 小时前
近期零基础量化学习:先分阶段,再用 AI 检查缺口wp123_112 小时前
硬件元器件笔记|IPX8 防水 Type‑C 母座安费诺 124018802112A 与 TONEVEE TY48086‑24A 分析wuyk55512 小时前
4.树:一对多的层次数据结构清水白石00812 小时前
Python 死锁排查全攻略:从线程卡死到锁依赖定位与工程化修复Elias不吃糖13 小时前
Langfuse 入门:Trace、Prompt、Dataset、Experiment、Evaluatorluj_176813 小时前
桥牌思维启示:系统设计的模块化架构TechWayfarer13 小时前
批量查IP归属地,在线API、脚本、离线库怎么选?三种方案实测对比