This tutorial shows how to send a icmp ping packet with Python and Scapy. The tool which is named as L3 troubleshooting tool sends a ping packet to the destination and prints the response.
The 1st step is to create a python file using the command vi l3tshoot.py following which the following code is entered.
Line wise code explanation is provided below.
1. Imports the logging module
2. Calls the appropriate function in the logging module.
3. Imports scapy
4. Takes the IP address for which the status has to be checked and stores it in the variable dstip
5. Creates an ICMP header
6. Associates the ICMP type value as 8
7. Associates the ICMP code value as 0
8. Creates an IP header.
9. Associates the destination IP address in the IP header with the value taken from the user.
10. Sends the packet on the network with a timeout set.
11. If statement for checking if the packet has been received.
12. Prints the layer 3 status is upon receipt of packet
13. Else statement
14. Prints the layer 3 status is down.
The code is executed from the Ubuntu command line using the following command
sudo python l3tshoot.py