pcap python 生成_如何从pcap文件信息生成图形

这段代码展示了如何使用Python的Scapy和Graphics库从pcap文件中读取源IP地址,并根据出现次数生成条形图。用户输入文件名后,程序将显示每个源IP的发送包数及其比例条形。
摘要由CSDN通过智能技术生成

对于任何好奇或处理类似问题的人,以下是我的最终(工作)代码:

from graphics import *

from scapy.all import *

from collections import Counter

def main():

filename = str(raw_input("What is the name of the file? "))

# sets packet source IPAs to sources, sourcenum also has # of occurrences

IP.payload_guess = []

sources = list((p[IP].src) for p in PcapReader(filename) if IP in p)

sourcenum = collections.Counter(sources)

print sourcenum

def makegraph():

howmany = sum(1 for x in sourcenum.values())

width = 1000/howmany

# creates graph window with white background

win = GraphWin("Packets Sent From Certain Addresses", 1080, 360)

win.setBackground("white")

Line(Point(80, 330), Point(1080, 330)).draw(win)

Line(Point(80, 0), Point(80, 330)).draw(win)

# creates

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值