• Kyser Clark

100 Days of Code - Day 68



I DID IT. I automated my first router configuration! Of course, it's a simple script, but it's still automation nonetheless.


Continuing with the Python Network Programming for Network Engineers Udemy Course by David Bombal, I learned how to get Cisco IOS images running in GNS3 (after paying $200 for Cisco Modeling Labs), and I set up a simple topology (see figure 1). Once the topology was created, I made a simple script that configured a loopback address and a basic OSPF configuration on Router 1. The NetworkAutomation computer is a Linux machine that can telnet to devices and run any scripts stored on the device.


Figure 1


The basic script:

import getpass
import telnetlib

HOST = "192.168.122.71"
user = input("Enter your telnet username: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until(b"Username: ")
tn.write(user.encode('ascii') + b"\n")
if password:
    tn.read_until(b"Password: ")
    tn.write(password.encode('ascii') + b"\n")

tn.write(b"enable\n")
tn.write(b"Kyser\n")
tn.write(b"conf t\n")
tn.write(b"int loop 0\n")
tn.write(b"ip add 1.1.1.1 255.255.255.255 \n")
tn.write(b"router ospf 1 \n")
tn.write(b"network 0.0.0.0 255.255.255.255 area 0 \n")
tn.write(b"end\n")
tn.write(b"exit\n")

print(tn.read_all().decode('ascii'))

Total Time Dedicated to Python Learning = 179.5 hours

6 views

Related Posts

See All