Advertisement
TJJT

bu

Dec 21st, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. import getpass
  3. import sys
  4. import telnetlib
  5.  
  6. user = raw_input("Enter your remote account: ")
  7. password = getpass.getpass()
  8.  
  9. #open the file that contains the devices IP address
  10. f = open("laitteet.txt")
  11.  
  12. #build For loop to check to do the below on all the devices
  13. for line in f:
  14. print "sanity checks for Router" + " " + (line)
  15. HOST=line
  16. telnet = telnetlib.telnet(HOST)
  17. telnet.read_until('Username: ')
  18. telnet.write(user + "\n")
  19. if password:
  20. telnet.read_until("password:")
  21. telnet.write(password + "\n")
  22.  
  23. #write all the commands needed to be done on all the devices
  24. telnet.write("show version\n")
  25. telnet.write("show inventory\n")
  26. telnet.write("show ip int brief\n")
  27. telnet.write("exit\n")
  28. #readoutput variable is to read all the output from telnet
  29. readoutput = tn.read_all()
  30.  
  31. # by default the File opened is read only , so we need also to enable writing
  32. saveoutput = open ("router" + " " + HOST +.txt , "w")
  33.  
  34. #write the output in readoutput variable in saveoutput
  35. saveoutput.write (readoutput)
  36.  
  37. #save the File
  38. saveoutput.close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement