Guest User

Untitled

a guest
Mar 2nd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import getpass
  4. import telnetlib
  5.  
  6. #Ask for username and password
  7. user = raw_input("Enter your telnet username: ")
  8. password = getpass.getpass()
  9.  
  10. #Open a file called myswitches
  11. f = open('myswitches')
  12.  
  13. #Telnet to switches and get run-configs
  14. for n in f:
  15. print "Getting running config from switch " + n
  16. HOST = n.strip()
  17. tn = telnetlib.Telnet(HOST)
  18.  
  19. tn.read_until("Username: ")
  20. tn.write(user + "\n")
  21. if password:
  22. tn.read_until("Password: ")
  23. tn.write(password + "\n")
  24.  
  25.  
  26. tn.write("terminal length 0 \n")
  27. tn.write("show run\n")
  28. tn.write("exit\n")
  29.  
  30. #read the output and save to files
  31. readoutput = tn.read_all()
  32. saveoutput = open("switch" + HOST, "w")
  33. saveoutput.write(readoutput)
  34. saveoutput.close
Add Comment
Please, Sign In to add comment