crt的python脚本crt标红了

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了crt的python脚本crt标红了相关的知识,希望对你有一定的参考价值。

使用python语言实现SecureCRT中的Dialog功能

# $language = "Python"
# $interface = "1.0"

#crt.Dialog.FileOpenDialog([title,[buttonLabel,[defaultFilename,[filter]]]])
#弹出一个对话框,用于选择单个文件;如果选择了具体文件则返回该文件的绝对路径,如果选择了弹窗的“取消”,则返回空。
filePath = crt.Dialog.FileOpenDialog("please open a file","open","a.log","(*.log)|*.log")
#filePath = crt.Dialog.FileOpenDialog("","","a.log","")
#crt.Dialog.MessageBox(message, [title, [icon|buttons]]) 警告、按钮类型弹出一个消息框,可以定义按钮,使用按钮和文本消息来实现和用户的简单对话;
crt.Dialog.MessageBox(filePath,"",64|0)
crt.Dialog.MessageBox("会话已断开","session",64|2)
crt.Dialog.MessageBox("确认是否退出","session",32|1)
crt.Dialog.MessageBox("确认是否退出","session",32|3)
crt.Dialog.MessageBox("是否继续安装","session",32|4)
crt.Dialog.MessageBox("此会话已打开","session",48|5)
crt.Dialog.MessageBox("无法连接此窗口","session",16|6)

#crt.Dialog.Prompt(message [, title [,default [,isPassword ]]])
#弹出一个输入框,用户可以填写文字,比如填写文件名,填写路径,填写IP地址等,运行结果如果点击'ok',返回输入的字符串,否则返回""
password = crt.Dialog.Prompt("password","session","admin",False)
crt.Dialog.MessageBox(password,"password",64|0)
password = crt.Dialog.Prompt("password","session","",True)
crt.Dialog.MessageBox(password,"password",64|0)
(2)使用python语言实现SecureCRT中的Screen功能
参考技术A Python脚本是一种动态编程语言,它可以被用来编写脚本、编写程序和编写应用程序。与其他编程语言不同,Python可以被用来快速创建可扩展的应用程序。
Python的语法是清晰的,易于理解,使用Python可以以更少的代码实现更多的功能,因此可以节省时间和资源,提高程序的可维护性和可重用性。
Python可以用来开发一些复杂的程序,如游戏、网络应用程序、科学计算等,它还可以被用来作为脚本语言,用来自动化一些任务,如数据库管理、系统管理等。
Python支持多种编程范式,如面向对象编程、函数式编程、过程式编程等,它还支持大量的第三方库,可以方便的使用这些库来实现更多的功能。
此外,Python有一个非常活跃的社区,社区成员不仅可以提供帮助,还可以分享最新的编程经验和技术。
参考技术B Python脚本可能出现了语法错误,你可以通过检查Python脚本中可能出错的地方来修正它。

python脚本来控制SecureCRT

对于不熟悉VB语法的童鞋们,不妨使用python来操作CRT命令行。


如下代码:

#$language = "Python"
#$interface = "1.0"

def Main():
    tab = crt.GetScriptTab()

    if tab.Session.Connected != True:
        crt.Dialog.MessageBox(
            "Error.\n" +
            "This script was designed to be launched after a valid "+
            "connection is established.\n\n"+
            "Please connect to a remote machine before running this script.")
        return

    tab.Screen.Synchronous = True

    while True:
        tab.Screen.Send(‘\n‘)
        
        tab.Screen.WaitForStrings("Username:")
        tab.Screen.Send("admin" + ‘\n‘)
        
        tab.Screen.WaitForStrings("Password:")
        tab.Screen.Send("adc.admin" + ‘\n‘)
        
        tab.Screen.WaitForStrings("host>")
        tab.Screen.Send("enable" + ‘\n‘)
        
        tab.Screen.WaitForStrings("host#")
        tab.Screen.Send("copy tftp 192.168.10.110 bos_jx.bin ver" + ‘\n‘)
        
        tab.Screen.WaitForStrings("Install /mnt/boot/bcm.reset")
        tab.Screen.Send(‘\n‘)
        
        tab.Screen.WaitForStrings("host#")
        tab.Screen.Send("reboot" + ‘\n‘)
        
        tab.Screen.WaitForStrings(‘The system will be rebooted! Please enter "y/n"  to confirm:‘)
        tab.Screen.Send("y" + ‘\n‘)

#---------------------------main--------------------------------                    
Main()


更多精彩请参考官方文档:
https://www.vandyke.com/support/securecrt/python_examples.html

本文出自 “Dalon 技术博客” 博客,请务必保留此出处http://ybtest.blog.51cto.com/1941531/1933576

以上是关于crt的python脚本crt标红了的主要内容,如果未能解决你的问题,请参考以下文章

crt自动化脚本

python脚本来控制SecureCRT

SecureCRT中python脚本编写学习指南

用 Python实现一个ftp+CRT

python3.7安装提示api-ms-win-crt-runtime-|1-1-0.dll

windows 安装python3.5启动报错:api-ms-win-crt-runtime-l1-1-0.dll丢失