0

I am trying to capture incoming packets while sending continues packets in an interface (interval - 1 pps) using scapy. I tried sniff function with different parameters associated with it (ex. prn). But it didn't worked, since sniff not completes the action (sniffinf) to proceed send packets or not capturing packets in background.

My Requirements:

  1. Start capture using scapy
  2. Send traffic/packets
  3. stop capture using scapy

Tried:

sniff(iface="eno2") <-- This listen for packets to capture (Actually Peer will send packets once it receives packets from this interface(control packets exchanges) sendp(pkt, iface="eno2") <--- This command not get executed since sniff execution not complete

Thanks.

  • You could supply the `prn` argument to react to packets as the come in: `def callback(pkt): pkt.show(); sniff(iface="eno2", prn=callback, store=False)` – Carcigenicate Jun 08 '21 at 16:28

2 Answers2

0

Use AsyncSniffer

from scapy.sendrecv import AsyncSniffer, send
a = AsyncSniffer()
a.start()
send(IP(dst="www.google.com")/ICMP(), inter=1, count=30)
results = a.stop()

I used count to have some sort of way of stopping sendp

Cukic0d
  • 5,111
  • 2
  • 19
  • 48
0

You can try AsyncSniffer like Cukic0d stated or you can just create a Python thread which targets your sniffing function.

import threading
thread = threading.Thread(target=sniff_def, args=(arg1, arg2,))
thread.start()
Lloen
  • 68
  • 4
  • 11