Creating a packet with Scapy
As we know, the basic unit of network communication is a packet. So we can start by creating a packet with Scapy. Scapy creates packets in layers; each layer is nested inside its parent layer.
Getting ready
As we require a Scapy module to be installed in the environment, make sure to install it with the pip
command:
pip install scapy
After installation, make sure it's working by issuing the scapy
command in your Terminal:
scapyWelcome to Scapy (3.0.0)>>>
This will open up an interactive Terminal for Scapy. You can also use this for basic debugging of Scapy scripts. A list of all the protocols supported by Scapy is as follows:
>>> ls()

Similarly, we can get the details and parameters in each protocol, as follows:
>>> ls(UDP)

How to do it...
Following are the steps to create packets with the scapy
module:
- Create a new file called
scapy-packet.py
and open it in your editor. - As usual, import the
scapy
module andpprint
for better readable printing:
from...