[Python] How to capture data from a TCP socket with scapy

Discussão em 'Python' iniciado por Stack, Dezembro 8, 2024.

  1. Stack

    Stack Membro Participativo

    I am creating a TCP socket:

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_sock:
    server_sock.bind((HOST, PORT))
    server_sock.listen()

    while True:
    sock, addr = server_sock.accept()


    Then I want to use scapy to capture packets from the socket. Right now, I'm doing it like this:

    data = sniff(iface = 'eth0', filter=f“port {PORT}”, count = 1)


    I receive one packet and send it to the queue. In a parallel process, I take packets from the queue and process them.

    I am receiving packets from a network interface using a socket port filter. Is there any way to receive packets using sniff directly from the socket?

    with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as server_sock:
    server_sock.bind((HOST, PORT))
    server_sock.listen()

    while True:
    sock, addr = server_sock.accept()
    while True:
    data = sniff(iface = 'eth0', filter=f“port {PORT}”, count = 1)

    Continue reading...

Compartilhe esta Página