• 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 = ""
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"conf t\n")
tn.write(b"int loop 0\n")
tn.write(b"ip add \n")
tn.write(b"router ospf 1 \n")
tn.write(b"network area 0 \n")


Total Time Dedicated to Python Learning = 179.5 hours


Related Posts

See All