Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import getpass
- import sys
- import telnetlib
- user = raw_input("Enter your remote account: ")
- password = getpass.getpass()
- #open the file that contains the devices IP address
- f = open("laitteet.txt")
- #build For loop to check to do the below on all the devices
- for line in f:
- print "sanity checks for Router" + " " + (line)
- HOST=line
- telnet = telnetlib.telnet(HOST)
- telnet.read_until('Username: ')
- telnet.write(user + "\n")
- if password:
- telnet.read_until("password:")
- telnet.write(password + "\n")
- #write all the commands needed to be done on all the devices
- telnet.write("show version\n")
- telnet.write("show inventory\n")
- telnet.write("show ip int brief\n")
- telnet.write("exit\n")
- #readoutput variable is to read all the output from telnet
- readoutput = tn.read_all()
- # by default the File opened is read only , so we need also to enable writing
- saveoutput = open ("router" + " " + HOST +.txt , "w")
- #write the output in readoutput variable in saveoutput
- saveoutput.write (readoutput)
- #save the File
- saveoutput.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement