In the previous video we learn how to configure ssh on cisco routers and mikrotik routers. 2
So now, we can remote the cisco and mikrotik router from our computer using ssh. 3
Well, in this video we will learn how to do network automation, we will learn about network 4
automation on cisco routers first. 5
We will learn about network automation on mikrotik routers in the next video. 6
Okay, let's get to the point, this is the script that we will use in this video 7
which is to do network automation on cisco routers. 8
I will also upload this script to the resources section, so you can download it, but I recommend 9
you to not copy and paste the code, you need to write the code by your self, so you can 10
understand the code easily. 11
Let’s understand the code, in the first line, we import paramiko, paramiko is python 12
library that we are going to use as a ssh client. 13
We also need to import time, I will explain later why we need to import time. 14
Here we define the ip address, username and password of the cisco router 15
We call SSH Client function from paramiko. 16
Then we connect to the router using the ip address, username, and password that we have 17
defined before. 18
Here, we print that we have successfully connected to the router, and then do invoke shell. 19
Here we can see that we send the cisco command to the router. 20
In this example I just send a command to configure loopback interface 0 with ip address 10.1.1.1. 21
Here you can see that I define time sleep 1, which means that the code will delay for 22
1 seconds, we need to make the code wait for 1 seconds or the command will not sent to 23
the router successfully, we will try to remove the time sleep later and we will see the result. 24
Here we save the output of the cisco command that we have sent to the router 25
and then we print the output to the console. 26
Last, we need to close the ssh connection from the router. 27
Okay Now let’s run the code. 28
open the command prompt, and go to the directory where we save the code. 29
Let’s try to dir to make sure that we are in the right directory. 30
Here we can see that we have script.py. 31
Let’s run the code by command python script.py 32
Here we can see that we have successfully login to 192.168.1.3, which is the IP Address 33
of Cisco Router. 34
And then we also see that we have successfully send command to configure loopback interface 35
0 with ip address 10.1.1.1 to the cisco router. 36
Let’s go to the cisco router and type show ip interface brief 37
here we can see that now we have loopback 0 with ip address 10.1.1.1. 38
Congratulations! 39
You are successfully doing your first Network Automation! 40
Last for this video, I want to show you how if I remove the time sleep from the code. 41
Here remove time sleep. 42
I will change the loopback interface and the ip address, 43
Now save the code, and run it again. 44
Look, the command is not sent to the router successfully, let’s go to the cisco router 45
and type show ip interface brief, we also not see the interface loopback 1 here. 46
Now let’s put the time sleep again to the code. 47
Save the code, And run it again. 48
Cool ! the command sent to the router successfully, let’s make sure again in the cisco router, 49
now we have interface loopback 1 with IP Address 10.1.1.2 here 50
Congratulation ! now you are able to write a simple script for network automation on cisco router 51
In the next video, we are going to learn simple script for network automation on mikrotik router 52
Thankyou for watching and See you on the next video.