Wednesday, 13 September 2017

Python for network engineer:- Configure Cisco router using Python2.7

We tried to configure loopback0 on the router using python. Same script can be used to configure anything on the router. We just need to add telnet.write command to configure the cisco router.

import telnetlib

user = "test"
password = "test"

HOST = "192.168.1.100"

telnet = telnetlib.Telnet(HOST)

telnet.read_until("Username: ")
telnet.write(user + "\n")
telnet.read_until("Password: ")
telnet.write(password + "\n")
telnet.write("conf t\n")
telnet.write("int lo0\n")
telnet.write("ip address 1.1.1.1 255.255.255.0\n")
telnet.write("end\n")
telnet.write("exit\n")
print telnet.read_all()

=== output===

R1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
R1(config)#int lo0
R1(config-if)#ip address 1.1.1.1 255.255.255.0
R1(config-if)#end
R1#exit

No comments:

Post a Comment