Network automation using Python

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.

Step 1

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.

Step 2

Download and install Scapy using the command yum install scapy or the synaptic package manager.

Step 3

Create a Python file and import scapy. The command from scapy.all import * can be used.

Step 4

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.

Python Network programming and Automation Course on Udemy

Step 5

Execute the code to get the following output.

Step 6.

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.

Python Network programming and Automation Course on Udemy