This example shows how to build an ARP request packet with scapy.
The above source code shows the script developed with scapy which is used to build and send an ARP request packet.
The line by line code explanation is provided below.
1. The first line ether=Ether() creates an ethernet header.
2. The second line ether.src=’00:10:ec:3c:22:b4′ associates the source mac-address in the ethernet header with the sender mac-address. This is the mac-address of the system where scapy is installed.
3. The third line ether.dst=’FF:FF:FF:FF:FF:FF’ associates the destination mac-address in the frame as broadcast. ARP request packets are broadcast in nature, due to which the destination field is saved as broadcast.
4. The fourth line arp=ARP() creates an ARP header.
5. The fifth line ls(ARP) displays the contents of the ARP header.
6. The sixth line arp.op=1 specifies the arp packet type as arp request.
7. The seventh line arp.hwsrc=’00:e0:1c:3c:22:b4′ associates the sender mac-address in the ARP header as ’00:01:ec:3c:22:b4′
8. The eight line arp.hwdst=’00:00:00:00:00:00′ associates the target mac-address field in the ARP header as null since this is filled by the destination.
9. The ninth line arp.psrc=192.168.1.25 associates the sender IP address field in the ARP header as 192.168.1.25, which the is the IP address of system on which the code is executed.
10. The tenth line arp.pdst=192.168.1.100 associates the destination IP address in the ARP header as 192.168.1.100
11. The 11th line sendp(ether/arp) sends the ARP packet on the network.
Learn how to build your own network tools with Python and scapy with our course. The course contains examples and projects which help you how to to integrate Python and scapy for network automation.
Click here to take the Course with Projects & Source Code on Udemy