I am rather new to programming and I was wondering y'all think the best way to configure a cisco router using python would be. currently I am using telnetlib. my problem is, I get an error after connecting to the router. here is the error I get when I use IDLE:
Enter IP: 205.180.0.3
Warning: Problem with getpass. Passwords may be echoed.
Router Password: cisco
Warning: Problem with getpass. Passwords may be echoed.
Router Secret: class
Enter Router hostname: RouterBob
Traceback (most recent call last):
File "C:\Documents and Settings\bob\My Documents\Administration\Scripts\cisco_config.py", line 20, in ?
tn.write("hostname " + hostName + "\n")
File "C:\Python24\lib\telnetlib.py", line 292, in write
self.sock.sendall(buffer)
File "<string>", line 1, in sendall
error: (10053, 'Software caused connection abort')
>>>
I have also attached the script that I use. could you please point me in the right direction.
thank you in advance,
--
Daniel McQuay
boxster.homelinux.org
Dead Possum Productions
814.825.0847
import getpass import sys import telnetlib HOST = raw_input("Enter IP: ") password = getpass.getpass('Router Password: ') secret = getpass.getpass('Router Secret: ')
tn = telnetlib.Telnet(HOST) tn.write("\n") tn.write("\n") tn.read_until("Router>") #what if it's configured already? tn.write(password + "\n") tn.write("enable\n") tn.write(secret + "\n") tn.write("config t\n") #User input for router config hostName = raw_input("Enter Router hostname: ") tn.write("hostname " + hostName + "\n") interface = raw_input("Enter interface to be configured: ") tn.write("int " + interface + "\n") intAddress = raw_input("Enter interface IP address and Subnet Mask: ") tn.write("ip address " + intAddress + "\n") intDesc = raw_input("Enter description for interface: ") tn.write("desc " + intDesc + "\n") bannerMOTD = raw_input("Enter the Message of the day: ") tn.write("banner motd " + bannerMOTD + "\n") lineCON = raw_input("Enter CON password: ") tn.write("line con 0\n") tn.write("password " + lineCON + "\n") tn.write("login\n") lineAUX = raw_input("Enter AUX passowrd: ") tn.write("line aux 0\n") tn.write("password " + lineAUX + "\n") tn.write("login\n") lineVTY = raw_input("Enter VTY password: ") tn.write("line vty 0 4\n") tn.write("password " + lineVTY + "\n") tn.write("login\n") tn.write("exit\n") tn.write("show run\n") confirm = raw_input("Press Enter To Close:") tn.close()
_______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor