For a personnal project, I need to capture packets. I've done it on the port I put as an example in the code below that I tested. The application I'm interested in communicates on this port and as soon as it's on (and the program is running), I have a packet exchange. I tested by replacing prn
by prn = lambda x: x.summary()
My issue is the following. I'd like to retrieve the contents of the RAW
layer for packets that have it. A solution would be to make pkt[3]["RAW"].load()
with 3 in index
, but this doesn't work with count = 0
, I want to retrieve packets continuously.
So my idea was to make a function that for each packet checks if it has a RAW
layer. If it does, it displays its load
field. However my code as it is doesn't work without index. I thought of a foreach loop but without success.
Do you have an idea how to proceed ? Here is what I have in the current state.
from scapy.all import *
def showData():
if (x.haslayer("RAW")):
#do a x[...]["RAW"].load()
pkt = sniff(count=0,filter = "tcp port 6800", prn = lambda x: x.showData())
Thanks in advance