scapy send packet explained

This tutorial explains the different layers at which you can send packets using scapy. Predominantly you can use two methods to send packets. The send command is used for appending and sending packets at the IP layer and the command sendp is used for appending and sending packets at the ethernet layer.

The details of both the command with examples are provided below.

scapy send command

The send command is used for sending packets at layer 3. The command is used for appending and sending IP packets. An example is shown below.

scapy send packet code

The above image shows how a ping packet is constructed and how to send the packet using the send command. Ping works at the network layer. To send a ping packet on the network, an IP header is required.

The command send(ip/icmp) would send the crafted ping packet appended with the ICMP header and the IP header.

The details of the code is included in our course on udemy Python Network Programming Course

scapy sendp command

The sendp command is used for sending packets at layer 2. The command is used for appending and sending ethernet packets. An example is shown below.

scapy sendp code

The above screenshot shows how to send an ARP packet with scapy. ARP is a protocol which works at layer 2 of the OSI model. To send an ARP packet on the network, an ethernet header would be required. The sendp command is used to append the ARP and ethernet headers and send the packet on the network.

send and sendp command – practical use

As explained above, both send and sendp commands have different use. Based on the type of protocol headers which needs to be crafted and send, the appropriate commands are used. For example to send layer 2 packets like STP and ARP custom layer 2 headers needs to be created. For this, the command sendp is used. To send packets which is not dependent on custom layer 2 headers like icmp, tcp, udp, the command send is used.

Check out our Python Network Programming Course on udemy which explains how to use Python & Scapy to build custom network tools & scripts