We have already created some packets in the previous recipe. Now we can send and receive those packets with Scapy.
Sending and receiving packets with Scapy
How to do it...
Following are the methods to send and receive packets with scapy module:
- Make sure to import the required modules:
from scapy.all import * from pprint import pprint
- We can use the send() function to send packets at layer 3. In this case, Scapy will handle the routing and layer 2 within it:
network = IP(dst = '192.168.1.1') transport = ICMP() packet = network/transport send(IP(packet)
This will send an ICMP packet
- To send a packet with custom layer 2, we have to use the sendp() method. Here we have to pass the interface to be used for sending...