Advertisement
Guest User

Untitled

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