Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- import switchlist as slist # returns 9 IP addresses
- import telnetlib
- username = 'admin'
- password = 'password'
- SwitchList = []
- text = []
- def telnetTo():
- try:
- for x in slist.AllSwitches:
- SwitchList.append(x[1])
- for x in SwitchList:
- tn = telnetlib.Telnet(x, timeout=5)
- tn.read_until('switch_')
- tn.write(username + "rn")
- if password:
- tn.read_until('Password: ')
- tn.write(password + 'rn')
- tn.write('enable rn')
- tn.write('show mac-address-table rn')
- tn.write('rn')
- tn.write('rn')
- time.sleep(2)
- tn.write('exit rn')
- tn.write('exit rn')
- my_text = tn.set_debuglevel(60000)
- my_text = tn.read_all()
- text.append(my_text)
- file = open('TelnetOutput', 'w')
- for x in text:
- file.write(x)
- file.write('END OF OUTPUT')
- file.close()
- except IOError:
- print(x + 'has timed out')
- pass
- telnetTo()
Add Comment
Please, Sign In to add comment