Pyshark无法通过PCAP进行迭代

时间:2019-01-09 20:44:32

标签: python wireshark pcap pyshark

我正在尝试从PCAP文件中提取一些相关的详细信息。我已经尝试过Pyshark和Scapy,但是每次尝试遍历文件时都会引发异常。

def process_pcap(pcap_file):
packet_stats = {}
log.info('Opening PCAP file')
packet_data = pyshark.FileCapture(pcap_file)
summaries = pyshark.FileCapture(pcap_file, only_summaries=True)
packets = zip(packet_data, summaries) 
log.info('Starting to parse PCAP file and collect stats')
for pkt, summary in packets:
    log.DEBUG(pkt.eth.scr, summary)
    # Count the total number of packets 
    if pkt.eth.scr or pkt.eth.dst in packet_stats.keys():
        total_packets[pkt.eth.dst][0] += 1   
    else:
        total_packets[pkt.eth.dst][0] = 1
        total_packets[pkt.eth.dst][1] = 0
    # Count the total number of retransmissions
    if 'retransmission' in summary.lower:
        total_packets[pkt.eth.dst][1] += 1 
log.info('Completed parsing and collecting stats')
return packet_stats

这将引发此错误-> RuntimeError:另一个循环正在运行时无法运行事件循环

有人遇到过这个问题吗?

0 个答案:

没有答案