当前位置:   article > 正文

[Python] Pyshark统计pcap的packet协议字段并柱状图可视化_pyshark only_summaries=

pyshark only_summaries=
import pyshark
import collections
import matplotlib.pyplot as plt
import numpy as np

cap = pyshark.FileCapture('pcap/netatmoweatherPOWER_3.pcap', only_summaries=True)
protocolList = []
for packet in cap:
    line = str(packet)
    formattedLine = line.split(" ")
    protocolList.append(formattedLine[4])
counter = collections.Counter(protocolList)

plt.style.use('ggplot')
y_pos = np.arange(len(list(counter.keys())))
plt.bar(y_pos, list(counter.values()), align='center', alpha=0.5, color=['b', 'g', 'r', 'c', 'm'])
plt.xticks(y_pos, list(counter.keys()))
plt.ylabel("Frequency")
plt.xlabel("Protocol Name")
plt.savefig("ProtocolGraph.png")
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

image-20220610150512023

报错解决

报的这个错

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/156828?site
推荐阅读
相关标签