Premkumar S
Premkumar S

Reputation: 9

Is there a way to capture packets in background and send packets using scapy?

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.

Upvotes: 0

Views: 2616

Answers (2)

Lloen
Lloen

Reputation: 68

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()

Upvotes: 0

Cukic0d
Cukic0d

Reputation: 5421

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

Upvotes: 1

Related Questions