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
相关推荐
Cyber4K5 小时前
【Python专项】进阶语法-系统资源监控与数据采集(1)Le_ee5 小时前
ctfweb:php/php短标签/.haccess+图片马/XXE苍煜6 小时前
Java开发IO零基础吃透:BIO、NIO、同步异步、阻塞非阻塞yong99906 小时前
MATLAB读取高光谱图像2zcode6 小时前
基于MATLAB的肝病风险评估与分期分析系统设计与实现小小de风呀6 小时前
de风——【从零开始学C++】(五):内存管理ooseabiscuit7 小时前
Laravel6.x核心优化与特性全解析折哥的程序人生 · 物流技术专研7 小时前
Java面试85题图解版(一):基础核心篇AllData公司负责人7 小时前
通过Postgresql同步到Doris,全视角演示AllData数据中台核心功能效果,涵盖:数据入湖仓,数据同步,数据处理,数据服务,BI可视化驾驶舱Hello.Reader7 小时前
算法基础(十)——分治思想把大问题拆成小问题