stevenfrst
4/5/2018 - 5:54 AM

Simple Network Automation On Cisco Devices

Simple Network Automation On Cisco Devices

import getpass
import sys
import telnetlib

HOST = "localhost"
user = raw_input("Enter Your Username: ")
password = getpass.getpass()

tn = telnetlib.Telnet(HOST)

tn.read_until("login: ")
tn.write(user + "\n")
if password:
    tn.read_until("Password: ")
    tn.write(password + "\n")

tn.write("enable\n")
tn.write("configure t\n")
tn.write("int lo1\n")
tn.write("ip add 1.1.1.1 255.255.255.255\n")
tn.write("no sh\n")
tn.write("exit\n")
tn.write("router ospf 1\n")
tn.write("net 0.0.0.0 255.255.255.255 area 0\n")
tn.write("do write\n")
tn.write("end\n")

tn.write("sh ip int bri\n")
print tn.read_all()