This article understands how network automation can be performed using Python. Scapy is a framework which is used for crafting and sending packets. Scapy can be combined with Python for automating and creating tools like packet injectors , network scanners, speed testers etc. The step by step procedure to integrate python with scapy is explained and the code along with the output is shown to create a custom TCP packet injector. The packet injector sends a SYN packet to any port on the destination system.
Download and install Python on any Linux flavor like Ubuntu. The command yum install python or the synaptic package manager can be used to install Python.
Download and install Scapy using the command yum install scapy or the synaptic package manager.
Create a Python file and import scapy. The command from scapy.all import * can be used.
Type in the following code. The functionality of the code is to take the port number and destination IP address from the user and send the packet on the network. The detailed explanation of the code is available in our Udemy Course.
Execute the code to get the following output.
The code sends the TCP packet with port 80 to the IP address 192.168.1.100.
Learn to write your own network automation tools and scripts with Python and Scapy with our Udemy Course.