# $language = "Python" # $interface = "1.0" # -*- coding: gbk -*- cmds = { '5800':{'waituser':'Username', 'user':'admin\r', 'waitps':'assword', 'password':'appled\r', 'waitsigner':'>', "cmd1":'display current-configuration\r', 'cmd2':'dis device manuinfo | include DEVICE\r', 'cmd3':'display ip inter brief\r', 'cmd4':'display inter brief\r', 'cmd5':'display mac-address\r', 'cmd6':'display clock\r', 'qu':'qu\r', 'iplist':{'192.168.240.2':'鹿煤录脪脢戮路露脟酶脪碌脦帽PC-P-C202-3-3-NSW03', }, }, '5120':{'waituser':'Username', 'user':'admin\r', 'waitps':'assword', 'password':'appled\r', 'waitsigner':'>', 'cmd1':'display current-configuration\r', 'cmd2':'dis device manuinfo \r', 'cmd3':'display ip inter brief\r', 'cmd4':'display brief inter \r', 'cmd5':'display mac-address\r', 'cmd6':'display clock\r', 'qu':'qu\r', 'iplist':{'192.168.240.3':'鹿煤录脪脢戮路露脟酶鹿脺脌铆PC-P-C202-3-3-NSW01', '192.168.240.4':'鹿煤录脪脢戮路露脟酶ipmiPC-P-C202-3-3-NSW05', '192.168.240.7':'鹿煤录脪脢戮路露脟酶鹿脺脌铆PC-P-C202-C-6-5-NSW01', }, }, '55102':{'waituser':'Username', 'user':'admin\r', 'waitps':'assword', 'password':'appled\r', 'waitsigner':'>', 'cmd1':'display current-configuration\r', 'cmd2':'dis device manuinfo | include DEVICE\r', 'cmd3':'display ip inter brief\r', 'cmd4':'display inter brief\r', 'cmd5':'display mac-address\r', 'cmd6':'display clock\r', 'qu':'qu\r', 'iplist':{'192.168.240.5':'鹿煤录脪脢戮路露脟酶脪碌脦帽碌露脝卢YPT-202-6-5-BSW01', '192.168.240.6':'鹿煤录脪脢戮路露脟酶麓忙麓垄碌露脝卢YPT-6-5-202-BSW03', }, }, 'ciscofc':{'waituser':'login', 'user':'admin\r', 'waitps':'assword', 'password':'apple@123\r', 'waitsigner':'#', 'cmd1':'show running-config\r', 'cmd2':' show module \r', 'cmd3':'show ip interface \r', 'cmd4':'show int brief \r', 'cmd5':'show port-license\r', 'cmd6':'show clock\r', 'qu':'exit\r', 'iplist':{'192.168.240.8':'鹿煤录脪脢戮路露脟酶麓忙麓垄ciscofc PC-P-C202-C-3-3-FSW01', }, }, } #print cmds['55102']['user'] # Connect to a telnet server and automate the initial login sequence. # Note that synchronous mode is enabled to prevent server output from # potentially being missed. def whoel(command): crt.Screen.Send(command) while True: if crt.Screen.WaitForString("More",5): crt.Screen.Send(" ") else : break def main(ios): crt.Screen.Synchronous = True for i in cmds[ios]['iplist'].keys() : crt.Session.LogFileName = ('Telnet %s' %(i)) #crt.Session.LogFileName = ('TELNET whoel 192.168.240.4 23.txt') crt.Session.Log(True,True) # connect to host on port 23 (the default telnet port) # #crt.Session.Connect("TELNET 172.16.25.254 23") crt.Screen.Send("TELNET %s 23 \r" %(i)) if crt.Screen.WaitForString('Press')==-1: whoel(cmds[ios]['qu']) crt.Session.Log(False) crt.Screen.Synchronous = False else: crt.Screen.WaitForString(cmds[ios]['waituser']) crt.Screen.Send(cmds[ios]['user']) crt.Screen.WaitForString(cmds[ios]['waitps']) crt.Screen.Send(cmds[ios]['password']) crt.Screen.Synchronous = False crt.Screen.WaitForString(cmds[ios]['waitsigner']) whoel(cmds[ios]['cmd1']) whoel(cmds[ios]['cmd2']) whoel(cmds[ios]['cmd3']) whoel(cmds[ios]['cmd4']) whoel(cmds[ios]['cmd5']) whoel(cmds[ios]['cmd6']) whoel(cmds[ios]['qu']) crt.Session.Log(False) crt.Screen.Synchronous = False #main('ciscofc') main('5800') main('5120') main('55102') main('ciscofc')