python 控制SecureCRT运行脚本

测试工作,经常用到SecureCRT,做了一个最笨的python 脚本来控制CRT ,在运行脚本。

实现原理就是用pyautogui 来模拟快捷键。

#coding=utf-8

import pyautogui as pg

import os

import time

scriptpath= ‘D:\script’

#开启CRT软件

def openoltcrt():

    os.system(r” start D:\SecureCRT\SecureCRT.exe”)#CRT 软件放在D盘的 ,用这句来打开CRT

    pg.press(‘enter’) #打开 CRT 后要选择你的连接。

    time.sleep(2)

python 控制SecureCRT运行脚本

 

#关闭CRT软件

def closecrt():

    pg.hotkey(“alt”,”f4″) #用快捷键来关闭 CRT 软件

    pg.press(‘y’) #关闭 CRT 软件,按Y 来确认你要关闭。

#在CRT软件里面运行脚本

def runscript(scriptpath,script):

    pg.keyDown(‘alt’)

    pg.press(‘s’) #按快捷键ALT+S 来 选择script 菜单

    time.sleep(1)

    pg.press(‘r’) #script 菜单出来了按r 来运行脚本

    pg.keyUp(‘alt’) #ALT 键要释放出来,不然要出问题。

    time.sleep(1)

    crt_script_path = str(scriptpath)

    # 调用脚本打开连接

    script1 = os.path.join(crt_script_path, str(script)) # 脚本存放路径,和脚本的名字

    pg.write(script1)

    time.sleep(5)

    pg.press(‘enter’)

    time.sleep(10)

CRT 里面运行的python 脚本 

将下面的脚本保存为test.py

# $language = “python”

# $interface = “1.0”

import time

def dhcpserverchange(mode):

      crt.Screen.WaitForString(“administrator@raspberrypi:~$”,2)

      crt.Screen.Send(“sudo cp /etc/dhcp/dhcpd6_”+str(mode)+”.conf /etc/dhcp/dhcpd6.conf\r\n”)    

dhcpserverchange(“mape”)

本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://www.net2asp.com/b3bd09d584.html