In the previous video, We already create a script to looping in the list ip address. 2
So here we have a list that save the ip address of all router, and then we do looping to this list. 3
But if you remember, the ip address of loopback is same on all router, which is 10.5.1.1. 4
Now, we are going to modify this script, so the last number in the loopback ip address 5
will based on the last number in the router ip address. 6
Here we have the ip address list of all router, so we will use the last number, 7
which is 1 2 3 4 and 5. 8
And then this last number will used in the loopback ip address. 9
How we can do that? 10
Let’s try it in the python interpreter first. 11
Copy this, go to terminal, and then go to python interpreter. 12
Let’s clear this using ctrl + l. and then paste the script. 13
Let’s print the list_ip, 14
Okay this is the list. 15
Let’s try to looping here, for ip in list_ip, and then print the ip, 16
Here we get the ip address of all router, 10.1, 10.2, 10.3, 10.4, and 10.5. 17
Here we can see that the data type of each ip address is tring, here we have a quote, 18
this is means string. 19
Let’s check it, up arrow until we see the looping again, and then here let’s print 20
the type of ip. 21
Here we can see that the type is string. 22
In the string, we have method split, this method will split the string become a list. 23
Let’s try it, 24
For ip in list_ip, and then let’s try to split this ip, ip_split, this is just a variable, 25
And then ip.split(“.”), this is means that we split the ip based on dot . 26
So the result will be a list, 10 10 10 and then 1, let’s print the ip_split here. 27
Enter 2 times, 28
Okay this is router 1, this is router 2, this is router 3, this is router 4, and this is router 5. 29
Okay so now we can access the last number using indexing. 30
In python, the index is started by 0, so here 0 1 2 3, so the index of last number is 3, 31
or we also can use reverse indexing 32
Reverse indexing is start from the last item, the index of last item is -1. 33
Okay now let’s try to print the last number. 34
For ip in list_ip, ip_split ip.split dot, and then let’s print the ip_split index 3, 35
Or you can also using reverse indexing, so the index will be -1. 36
Enter 2 times, 37
Okay here we get 1 2 3 4 and 5, 38
We will use this number as the ip address of loopback interface, so the ip address of 39
loopback interface for each router will be different. 40
Now let’s back to sublime, here let’s take the last number of the ip address like 41
we already do in the python interpreter. 42
Router_id, this is just a variable, you can use anything. 43
And then ip.split, dot, so we split the ip based on dot. 44
And then here let’s access the index -1, which is the last item. 45
Next, let’s configure for loopback5, 46
The ip address is 10.6 and then here will be based on router_id, so we use f string, 47
And then here router_id. 48
Okay save, back to therminal, exit from interpreter, 49
And then here let’s execute the script, python paramiiko_looping_list.py, 50
enter enter here, 51
Okay here we success on router 1, the ip address is 10.6.1.1, 52
Router 2 also success, the ip address is 10.6.1.2, 53
Router 3, also success, the ip address is 10.6.1.3, this is 3. 54
Router 4 also success, this is 4. 55
And last, router 5 also success, this is 5. 56
Okay I think enough for this video 57
Thankyou for watching and see you on the next video.