Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pexpect
- import time, sys, os
- class CleanFile(file):
- def write (self, text):
- # Remove the whitespaces
- out_text = ''
- # process the backspace properly
- bline = ''
- for c in text:
- if (ord(c) == 0x8):
- if (len(bline) == 0):
- # Move the file pointer.
- file.seek(self, -1, os.SEEK_CUR);
- else:
- bline = bline[:-1]
- else:
- bline += c
- # remove whitespaces from inside a line
- out_text += ''.join(c for c in bline if (ord(c) >= 32 or ord(c) == 10));
- file.write(self, out_text);
- username = "admin"
- password = "admin"
- fout = CleanFile ("switch-config.log", 'w')
- for i in xrange(1, 13):
- child = pexpect.spawn('telnet %s' % ("mgmtsw" + str(i)))
- child.timeout = 3
- child.logfile = fout
- child.expect('login:')
- child.sendline(username)
- child.expect('password:')
- child.sendline(password)
- child.expect('#')
- child.sendline('disable sharing 1:1')
- child.expect('#')
- child.sendline('disable sharing 1:3')
- child.expect('#')
- child.sendline('disable sharing 2:1')
- child.expect('#')
- child.sendline('disable sharing 2:3')
- child.expect('#')
- child.sendline('configure vlan default add ports 1:1,1:3,2:1,2:3 untagged')
- child.expect('#')
- child.sendline('exit')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement