Layering packets
In Scapy, each packet is a collection of nested dictionaries, as Scapy uses Python dictionaries as the data structure for packets. Starting from the lowest layer, each layer will be a child dictionary of the parent layer. Also, each and every field inside the layer of a packet is a key value pair inside the dictionary for that layer. So, we can make changes in this field using the assignment operations.
How to do it...
To understand the layering in Scapy, we can go through the following steps:
- We can get the details of a packet and its layered structure using the
show()
method. We can use the interactive Terminal for inspecting and determining more about each packet's structure. Open up the Terminal and type the following:
>>> scapy
Next, create a packet and show its details, as follows:
>>> pkt = Ether()/IP(dst='192.168.1.1')/TCP(dport=80)>>> pkt.show()
Then it will print out the structure of the packet we created:

Even if we don't provide the source...