Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as Python by Fei Wang ( 9 years ago )
#! /usr/bin/env python
# -*- coding:utf-8 -*-
import os
import re
import sys
import telnetlib
import time
import datetime
def read_until(cue, timeout=2):
print tn.read_until(cue, timeout)
def main():
HOST = '100.100.67.2'
LOGIN_USER = 'pooh'
LOGIN_PASS = '2Ef5p6t1Z'
ENABLE_PASS = 'Kar2&tan4$'
f = open('cpe_pass_test.txt', 'r')
hostlist = f.readlines()
for line in hostlist:
Type = line.split(":")
CPE_IP = Type[1]
CPE_USER = Type[2]
CPE_PASS = Type[3]
CPE_ENPASS = Type[4]
CPE_HOST = Type[1] + ' /vrf MGMT /source g0/0/4'
CMD = open('cpe_tel_command.txt', 'r')
commandlist = CMD.readlines()
for line in commandlist:
time.sleep(1)
CMD.close()
try:
tn = telnetlib.Telnet(HOST)
tn.set_debuglevel(0)
# login
tn.read_until('Username:')
tn.write(LOGIN_USER + '\n')
tn.read_until('Password:')
tn.write(LOGIN_PASS + '\n')
# enable
tn.write('en' + '\n')
tn.read_until('Password:')
tn.write(ENABLE_PASS + '\n')
tn.read_until('#')
#tn = telnetlib.Telnet(CPE_HOST)
#tn.set_debuglevel(0)
# login CPE
tn.write(CPE_HOST + '\n')
tn.read_until('Username:')
tn.write(CPE_USER + '\n')
tn.read_until('Password:')
tn.write(CPE_PASS + '\n')
# enable
tn.write('en' + '\n')
tn.read_until('Password:')
tn.write(CPE_ENPASS + '\n')
tn.read_until('#')
# show log
tn.write('terminal length 0' + '\n')
tn.write('commandlist' + '\n\n')
log = tn.read_all()
#log = tn.read_until('\s').splitlines()
tn.write('exit' + '\n')
tn.read_until('#')
except EOFError:
print 'connection closed.'
for line in log:
print line
savelog = open ('tellog.txt', 'w')
savelog.writelines(log)
savelog.close()
print 'CPE check is DONE!'
sys.exit(0)
if __name__ == '__main__':
main()
Revise this Paste
Parent: 24817