对于任何好奇或处理类似问题的人,以下是我的最终(工作)代码:
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