SecureCRT 使用python脚本
转自:http://www.codeweblog.com/securecrt-python/
学完python后需要学以致用,但平时还真没有这个环境,也不搞自动化,但语言这玩意必需要用,就拿secureCRT来练手吧,也算是和工作擦点边
对话框加按扭
CONFIRM_REPLACE = """\ #为数不多的button判断
Do you want to replace the contents of "%(FILE)s" with the selected text? Yes = overwriteNo = appendCancel = end script"""
message = CONFIRM_REPLACE % { 'FILE' : filename }prompt = "Replace contents"buttons = BUTTON_YESNOCANCELresult = crt.Dialog.MessageBox(message, prompt, buttons)
if result == IDYES:fileMode = "w"
elif result == IDNO:fileMode = "a"
对话框取值
crt.Dialog.Prompt( #超级有用的在用户这获取数据的方式"Save selected text to file:","SecureCRT - Save Selected Text To File","MyFile.txt")
获取log文件名在SecureCRT
tab = crt.GetScriptTab() tab.Session.LogFileName #如果在CRT中设置了log文件名,这个函数可以把它读取出来 可以直接取到log的文件名
获取系统当前的前缀名
SCRIPT_TAB = crt.GetScriptTab() rowIndex = SCRIPT_TAB.Screen.CurrentRow colIndex = SCRIPT_TAB.Screen.CurrentColumn - 1 prompt = SCRIPT_TAB.Screen.Get(rowIndex, 0, rowIndex, colIndex) #获取当前行,当前列的数据,即该服务器的前缀,与waitfor配套 prompt = prompt.strip()
获取打印值
def CaptureOutputOfCommand(command, prompt):if not crt.Session.Connected:return "[ERROR: Not Connected.]"# First, send the command to the remote.SCRIPT_TAB.Screen.Send(command + '\r') #输入命令 cmmand 然后回车# Second, wait for the carriage return to be echoed by the remote device.# This allows us to capture only the output of the command, not the line# on which the command was issued (which would include the prompt + cmd).# If you want to capture the command that was issued, simply comment out# the following line of code.SCRIPT_TAB.Screen.WaitForString('\r') #等待命令输完后,服务器给的回应,这样可以不是获取行,而是获取输出# Now that the command has been sent, use Screen.ReadString to capture# all the data that is received up to the point at which the shell# prompt appears (the captured data does not include the shell prompt).return SCRIPT_TAB.Screen.ReadString(prompt) #获取直到prompt出现时的所有数据
屏幕取词
filename = os.path.join(os.path.expanduser('~'), 'output.txt') #~/output.txt fp = open(filename, "wb+") screenrow = crt.Screen.CurrentRow - 1 readline = crt.Screen.Get(screenrow, 1, screenrow, 20) #把当前行的1~20个字符取出来 fp.write(readline + os.linesep) #把取出的那一行加行尾符写到文件中
写到excel
import os import csv #excel module fileobj = open(filename, 'wb') worksheet = csv.writer(fileobj) worksheet.writerow(items[:2]) fileobj.close(
连接
SSH: cmd = "/SSH2 /L %s /PASSWORD %s /C 3DES /M MD5 %s" % (user, passwd, host) crt.Session.Connect(cmd) #ssh -L user password host Telnet: crt.Session.Connect("/TELNET 127.0.0.1 2034") # telnet 127.0.0.1:2034 crt.Session.Connect("/S \"" + session + "\"") #如果这个session在CRT里存在,无论是Telnet还是SSH都能连
调试工具 CRT中的print
crt.Dialog.MessageBox("Nothing to save!")
参考:
http://www.vandyke.com/support/securecrt/python_examples.html
SecureCRT 使用python脚本相关推荐
- SecureCRT中Python脚本编写学习指南
引言 在测试网络设备中,通常使用脚本对设备端进行配置和测试以及维护:对于PE设备的测试维护人员来说使用较多是SecureCRT工具:SecureCRT支持VB.JavaScript.Python等多种 ...
- 在secureCRT软件上运行一些简单的python脚本
secureCRT支持运行.js和.vbs以及.py格式的脚本,无奈mac上识别前两个格式的脚本只能写一写python脚本, 举个简单的例子,利用脚本直接ssh连接一台机器, 在View菜单中勾选 ...
- SecureCRT python 脚本
记录编写CRT的python脚本遇到的问题 向CRT的脚本传递参数的两种方式 一种是命令行的方式 /path/CRT.exe <filename>.py /ARG arguments / ...
- linux后台运行python脚本
&符号 这两天要在一直运行一个Python脚本,当然就想到了在命令后面加&符号 $ python /data/python/server.py >python.log & ...
- linux使得python后台运行,linux 下后台运行python脚本
&符号 这两天要在服务器端一直运行一个Python脚本,当然就想到了在命令后面加&符号 $ python /data/python/server.py >python.log & ...
- Linux环境python脚本后台运行
python 脚本后台运行 在服务器端一直运行一个Python脚本,当然就想到了在命令后面加&符号,代码如下: $ python /data/python/server.py >pyth ...
- 命令行运行Python脚本时传入参数的三种方式
三种常用的方式 如果在运行python脚本时需要传入一些参数,例如gpus与batch_size,可以使用如下三种方式. python script.py 0,1,2 10 python script ...
- Python脚本语言写法
Python脚本语言写法 脚本语言的开始行,是指文件中的代码用什么可执行程序去运行它,就这么简单. #!/usr/bin/python是告诉操作系统执行这个脚本的时候,调用/usr/bin下的pyth ...
- python 脚本撞库国内“某榴”账号
其实日常生活中我们的用户名和密码就那么几个,所以这给撞库带来了可能,本文主要给出python脚本撞库的一点粗浅代码.这里只讨论技术本生,代码中某榴的地址也已经改掉,避免被管理员误解禁言等发生,谢谢大家 ...
最新文章
- 【webpack】-- 模块热替换
- sklearn.feature_extraction.text.CountVectorizer 学习
- 【WPF】屏幕右下角消息提示框
- python前端学习-------Flask框架基础(建议收藏)
- linux centos7 安装最新版git 教程
- Maven项目中War包的打包及依赖方式
- 张正友相机标定Opencv实现以及标定流程标定结果评价图像矫正流程解析(附标定程序和棋盘图)
- python response重头开始_你必须学写 Python 装饰器的五个理由
- c语言一年日历程序,c语言日历程序
- java 怎么做批量修改_JAVA实现批量修改文件名称
- 炸!撩下 OLAP 数据分析的黑马神器 ClickHouse
- Elasticsearch系列—倒排索引原理
- 计算机组成原理学习 笔记三
- [Kafka][错误: 找不到或无法加载主类 Files\Java\jdk1.8.0_101\lib\dt.jar;C:\Program]
- 【XGBoost】第 7 章:使用 XGBoost 发现系外行星
- 一杯清茶!细品人生!
- AWS认证攻略 – E哥的AWS Solution Architecture Associate 认证攻略
- 使用json-server与Mockjs搭建模拟服务
- 美漂数据科学家年薪多少?爬了6年H1B签证数据发现,招的人多了,但钱少了
- 联想网御防火墙v3404_联想网御防火墙Power_V命令行操作手册.pdf
热门文章
- Mybatisplus-联表查询+二级缓存+if test
- html从入门到精通前锋,如何踢好业余足球,从入门到精通
- VFW-MFC视频采集
- 简笔画检索“Sketch Me That Shoe”
- 6.11 化学换肤与磨皮手术(1)
- 在vue中使用antV-G2展示基础饼状图
- oracle数据库之常用的函数练习
- 使用mysql编写学生期末成绩表的流程以及源码
- 万物智联与烟火人间,一场跨越20年的双向奔赴
- Alienware外星人原装系统出厂系统原机开箱系统远程安装,带F12恢复功能SupportAssist OS Recovery