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
相关推荐
卷无止境2 小时前
一人公司的全栈选型指南:让 AI Agent 写得快,也让生意跑得稳WJ.Polar3 小时前
Java封装、继承、多态摇滚侠4 小时前
Java 中如何表示负数,有符号和无符号的区别,补码的计算规则,char byte short int long 的范围滴啦嘟啦哒4 小时前
【具身笔记】【π0.5 微调与仿真】五、在MuJoCo中实现可视化仿真weixin_307779134 小时前
C++代码实现MATLAB中的fitrtree函数功能全栈练习生4 小时前
AI安全与红队测试爱读书的小胖4 小时前
Codewars:Rot13(C)解题分析费曼学习法4 小时前
把「发送成功」当「送达」?我排查 IM 长消息被静默吞掉的完整过程鸽鸽程序猿4 小时前
【项目】【在线判题系统】b端题目增删改Lhappy嘻嘻4 小时前
读懂 JVM:内存模型、类加载机制、分代回收