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
相关推荐
2601_963771375 小时前
10 Best PHP Media CMS and Scripts for Web Creators in 2026VIP_CQCRE5 小时前
用 Ace Data Cloud 快速接入 AI 视频生成:HappyHorse Videos API 实战指南阿里嘎多学长5 小时前
2026-07-09 GitHub 热点项目精选带娃的IT创业者5 小时前
监控并非安全:当隐私成为技术的祭品玖玥拾6 小时前
C# 语言进阶(十四)Unity UI界面开发 + 网络消息联动aaPIXa6226 小时前
C++ 质量前置检查:clang-format 与 clang-tidy 实践指南余额瞒着我当琳6 小时前
C++ 基础核心概念精讲:引用、内联与 nullptr阿豪只会阿巴6 小时前
两小时快速入门 FastAPI--第二回名字还没想好☜6 小时前
Go 内存逃逸分析:什么时候变量跑到堆上Ivanqhz6 小时前
NFM(神经因子分解机)