如何解决重叠间隔中的 Scapy 嗅探?
我想使用 Scapy 嗅探工具,就像一个窗口大小为 100 的滑动窗口。例如,它会嗅探网络数据包 0-100、120-220、140-240、160-260 等. 等。然后我的 Python 代码将绘制来自每个窗口的数据包。
但是我在网上找不到任何方法?此处提供的解决方案:Write packets captured with scapy sniff in time intervals 对我不起作用。
我现在拥有的代码如下。它目前只一遍又一遍地查看前 0-100 个数据包,这不是我想要的。但我无法弄清楚如何获得重叠的滑动窗口。我完全迷路了。在这一点上,一个时间窗口也可以,如果这会更容易的话。我只需要某种有效的滑动窗口。我应该怎么做?
当前代码:
import networkx as nx
from scapy.all import *
import matplotlib.pyplot as plt
IPList = []
count = 0
def parsePcap(pkts):
# for each packet in 100 packet window...
for pkt in pkts:
# if packet has IP layer
if pkt.haslayer(IP):
# get the src and dst IP address and append to list
x = pkt.getlayer(IP).src
y = pkt.getlayer(IP).dst
IPList.append((x,y))
return IPList
while True:
p = sniff(iface="br-780b04b207fb",count=100)
# convert window data to a list of src & dst IP addresses
IPOutput = parsePcap(p)
# plot the 100 packets in a network graph...
g = nx.DiGraph()
g.add_edges_from(IPOutput)
nx.draw_planar(g,with_labels=True,node_size=50)
plt.draw()
# save graph
filename = "digraph" + str(count) + ".png"
plt.savefig(filename)
count += 1
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。