Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import pexpect
  4. import time, sys, os
  5.  
  6.  
  7. class CleanFile(file):
  8. def write (self, text):
  9. # Remove the whitespaces
  10. out_text = ''
  11. # process the backspace properly
  12. bline = ''
  13. for c in text:
  14. if (ord(c) == 0x8):
  15. if (len(bline) == 0):
  16. # Move the file pointer.
  17. file.seek(self, -1, os.SEEK_CUR);
  18. else:
  19. bline = bline[:-1]
  20. else:
  21. bline += c
  22.  
  23. # remove whitespaces from inside a line
  24. out_text += ''.join(c for c in bline if (ord(c) >= 32 or ord(c) == 10));
  25.  
  26. file.write(self, out_text);
  27.  
  28. username = "admin"
  29. password = "admin"
  30. fout = CleanFile ("switch-config.log", 'w')
  31.  
  32. for i in xrange(1, 13):
  33. child = pexpect.spawn('telnet %s' % ("mgmtsw" + str(i)))
  34. child.timeout = 3
  35. child.logfile = fout
  36. child.expect('login:')
  37. child.sendline(username)
  38. child.expect('password:')
  39. child.sendline(password)
  40. child.expect('#')
  41. child.sendline('enable rip')
  42. child.expect('#')
  43. child.sendline('exit')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement