secure crt 脚本,securecrt,#$language =


#$language = "Python"#$interface = "1.0"#主机配置文件# ip  登录类型  登录用户 密码  归属系统   操作系统类型  记录日期   // 超级用户密码def config():    config_host_list=[        ["10.203.1.1","SSH2","szwg","*****","TD db1","solairs10","2011-03-18","*****"],        ["10.203.12.33","TELNET","szwg","****","TDserver02","solairs10","2011-03-18","******"]    ]    return config_host_list#导入主机配置数据ip_list=config()#导主配置文件 def get_hosts():    G_get_ip = crt.Dialog.Prompt("请输入主机:", "天名辅助", "132.108.19.1", False)    if G_get_ip == "":        crt.Dialog.MessageBox("主机信息有误")        return "no"    else:        return str(G_get_ip)      # User added datadef Create(check_ip):    check='n'    for i in ip_list:        if ( check_ip == i[0]):            G_ip=i[0]            G_type=i[1]            G_login=i[2]            G_passwd=i[3]            if (G_type == "SSH2"):                Mess("正在登录[SSH2]-->"+i[4])                crate_ssh2_session(G_ip,G_login,G_passwd)                crt.Screen.Synchronous = True                check='y'            elif (G_type == "TELNET"):                Mess("正在登录[TELNET]-->"+i[4])                crate_telnet_session(G_ip,G_login,G_passwd)                crt.Screen.Synchronous = True                check='y'            break    #配置文件中无相关设备信息,则自动退出程序    if (check=="n"):        crt.Dialog.MessageBox("配置文件中找不到相关设备信息")        crt.Quit()def exec_user_command(user_command):    if (crt.Screen.WaitForString(">", 3) != True):        crt.Screen.Send("exit \\n")    else:        crt.Screen.Send(user_command+" \\n")        SetStatusText("Mess" + user_command+" is running END")def crate_telnet_session(ip,login,passwd):    errcode = 0    try:        Temp_T_Tab=crt.Session.ConnectInTab("/TELNET "+ip)        Temp_T_Tab.Screen.WaitForString("ogin:",2)        Temp_T_Tab.Screen.Send(login+"\\r")        Temp_T_Tab.Screen.WaitForString("assword:",2)        Temp_T_Tab.Screen.Send(passwd+"\\r")        crt.Session.SetStatusText("TELNET<--->["+ip+"]")    except ScriptError:        errcode=crt.GetLastError()    if errcode !=0:        crt.Dialog.MessageBox("连接失败!网络不通或者配置有误")    else:        crt.Dialog.MessageBox("登录成功,请进行操作")def crate_ssh2_session(ip,login,passwd):    errcode = 0    try:        Temp_S_Tab=crt.Session.ConnectInTab("/SSH2 /PASSWORD "+passwd+" "+login+"@"+ip,True)        crt.Session.SetStatusText("SSH2<--->["+ip+"]")    except ScriptError:        errcode=crt.GetLastError()    if errcode !=0:        crt.Dialog.MessageBox("连接失败!网络不通或者配置有误")    else:        crt.Dialog.MessageBox("登录成功,请进行操作")def Mess(mess):    crt.Dialog.MessageBox("提示:"+mess)#start runip=get_hosts()if (ip != 'no'):    Create(ip)else:    crt.Dialog.MessageBox("配置文件中找不到相关设备信息")#result = crt.Dialog.MessageBox("Login Failed, Retry?", "Error", ICON_QUESTION | BUTTON_YESNO | DEFBUTTON2 )#if result == IDNO:#  return#该片段来自于http://byrx.net

评论关闭