Guest User

Untitled

a guest
Dec 30th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import time
  2. import switchlist as slist # returns 9 IP addresses
  3. import telnetlib
  4. username = 'admin'
  5. password = 'password'
  6. SwitchList = []
  7.  
  8. text = []
  9. def telnetTo():
  10. try:
  11. for x in slist.AllSwitches:
  12. SwitchList.append(x[1])
  13. for x in SwitchList:
  14. tn = telnetlib.Telnet(x, timeout=5)
  15. tn.read_until('switch_')
  16. tn.write(username + "rn")
  17. if password:
  18. tn.read_until('Password: ')
  19. tn.write(password + 'rn')
  20. tn.write('enable rn')
  21. tn.write('show mac-address-table rn')
  22. tn.write('rn')
  23. tn.write('rn')
  24. time.sleep(2)
  25. tn.write('exit rn')
  26. tn.write('exit rn')
  27. my_text = tn.set_debuglevel(60000)
  28. my_text = tn.read_all()
  29. text.append(my_text)
  30. file = open('TelnetOutput', 'w')
  31. for x in text:
  32. file.write(x)
  33. file.write('END OF OUTPUT')
  34. file.close()
  35. except IOError:
  36. print(x + 'has timed out')
  37. pass
  38. telnetTo()
Add Comment
Please, Sign In to add comment