Python: Get TCP session data on-fly with scapy

39 Views Asked by At

I try to get the defragment data with scapy. I read the instructions, made the initial code, but I don't understand what to do next

import struct

from scapy.sendrecv import sniff
from scapy.sessions import TCPSession


class NetPacket:

    def __init__(self, packet):
        self.packet = packet

    @classmethod
    def tcp_reassemble(cls, data, metadata, session):
        length = struct.unpack("!H", data[3:5])[0] + 5
        if len(data) == length:
            return NetPacket(data)


def process_packet(packet):
    tcp_packet = NetPacket(packet)
    print(tcp_packet)
    # data_stream.read(4) 

sniff(iface="xxx", prn=process_packet, filter="port xxxx", session=TCPSession)

what should I do next to start receiving the datastream and reading the necessary data?

I want to continue reading the data as data_stream.read(4)...

0

There are 0 best solutions below