print('发现 %d 个Pcap数据文件:' % (len(filenames))) for filename in filenames: print('\t', filename) print('\n开始转换,转换后数据将存入文件: %s\n' % (savefilename,))
withopen(savefilename, 'a', newline='') as f: fcsv = None# 公用csv writer对象,存入第一条数据前初始化 for filename in filenames: pkts = rdpcap(os.path.join(path, filename)) for pkt in pkts: if'IP'in pkt and'Ethernet'in pkt and'TCP'in pkt: # 调试发现Ethernet、IP、TCP对象都有fields属性,可以直接获取数据字典 e = pkt['Ethernet'].fields i = pkt['IP'].fields t = pkt['TCP'].fields