Python Scripting Learning Guide in SECURECRT

Source: Internet
Author: User
Tags button type clear screen

Introduction
    • In the test network device, the device side is usually configured and tested and maintained using scripts, and the SecureCRT tool is used more for the test maintenance personnel of PE equipment; SECURECRT supports many scripting languages such as VB, JavaScript, Python, etc. It is very useful to master the common functions of the CRT in order to implement the script more and more stably in the CRT. The next time I'm going to expand My learning application to the common functions of SECURECRT scripting.

content

(1) using Python language to implement dialog function in SecureCRT

# $language = "Python" # $interface = "1.0" #crt. Dialog.fileopendialog ([Title,[buttonlabel,[defaultfilename,[filter]]]) #弹出一个对话框 for selecting a single file, and if a specific file is selected, returns the absolute path to the file. If you select Cancel for the pop-up window, the return is empty. 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]]) Warning, button type pop-up a message box, you can define buttons, use buttons and text messages to implement a simple dialog with the user, CRT. Dialog.messagebox (FilePath, "", 64|0) Crt. Dialog.messagebox ("Session Disconnected", "Sessions", 64|2) Crt. Dialog.messagebox ("Confirm whether to exit", "session", 32|1) Crt. Dialog.messagebox ("Confirm whether to exit", "session", 32|3) Crt. Dialog.messagebox ("Continue Installation", "session", 32|4) Crt. Dialog.messagebox ("This session is open", "session", 48|5) Crt. Dialog.messagebox ("Unable to connect to this window", "Session", 16|6) #crt. DIALOG.PROMPT (message [, title [, default [, Ispassword]]) #弹出一个输入框, the user can fill in the text, such as fill in the file name, fill in the path, fill in the IP address, etc., run the results if you click ' OK ', Returns the input string, otherwise returns "" 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) using the Python language to implement the screen function in SecureCRT

# $language = "Python" # $interface = "1.0" # Currentcolumn returns the column coordinates of the current cursor. Curcol = Crt. Screen.CurrentColumncrt.Dialog.MessageBox (str (curcol)) # CurrentRow returns the line coordinates of the current cursor. Currow = Crt. Screen.CurrentRowcrt.Dialog.MessageBox (str (currow)) # Columns returns the maximum column width of the current screen cols = Crt. Screen.Columnscrt.Dialog.MessageBox (str (cols)) # rows returns the maximum line width of the current screen, rows = Crt. Screen.Rowscrt.Dialog.MessageBox (str (rows)) #IgnoreEscape defined when using waitforstring, Waitforstrings and ReadString These three methods when getting the escape character (special word such as carriage return) by default is obtained crt.Screen.IgnoreEscape = Falsecrt.Dialog.MessageBox ( Crt. Screen.readstring (["\03"],5)) #获取ctrl +ccrt. Screen.ignoreescape = Truecrt.Dialog.MessageBox (Crt. Screen.readstring (["\03"],2)) #不获取ctrl +c# Matchindex defines that when using the three methods of Waitforstrings and ReadString, the return value is obtained based on the position of the parameter, which is calculated starting from 1. If there is not a match, the 0.outPut = CRT is returned. Screen.readstring (["Error", "Warning", "#"],10) index = CRT. Screen.matchindexif (index = = 0): Crt. Dialog.messagebox ("Timed out!") elif (index = = 1): CRT. Dialog.messagebox ("Found ' Error '") elif (index = = 2): CRT. Dialog.messagebox ("Found ' WarniNg ' ") elif (index = = 3): CRT. Dialog.messagebox ("Found ' #") # Synchronous sets the synchronization properties of the screen. If set to false, there may be a loss of part of the data when using the Waitforstring, Waitforstrings, readstring functions in the script, and there may be a case of screen lag when set to true, and the default is FALSECRT. screen.synchronous = Truecrt.Screen.Send ("\ r \ n") Crt. Screen.readstring ("#") Crt. Screen.send ("\ r \ n") Crt. Screen.waitforstring ("#") Crt. Screen.send ("\ r \ n") Crt. Screen.waitforstrings (["#", ">"]) Crt. Screen.send ("conf t\r\n") # method # Clear () Clear Screen function # CRT. Screen.clear () # Get () takes the character of the screen in a rectangle by the coordinates (that is, starting from one column to the other column), without the carriage return line character in the string, so this is used to get the unformatted cursor string or a small segment of a specific area string. out = Crt. Screen.get (Row1, col1, Row2, col2) Crt. Dialog.messagebox (out) # Get2 () explains that the characters that are taken out of the screen in a rectangle in accordance with the coordinates (that is, starting from one column to the other column) contain the carriage return newline character in the string, so this is used to get a large segment of the formatted string. Crt. Screen.get2 (Row1, col1, Row2, col2) # IgnoreCase use global parameter settings to control the case sensitivity when using the three functions of waitforstring, waitforstrings, and ReadString. The default is False if the case string is checked, and the case is not detected when set to true. Crt. Screen.ignorecase = Truecrt.Screen.Send ("Show memory\r\n") Crt. Screen.waitforstring ("more") Crt. Screen.send ("\ r \ n") Crt. Screen.waitforstrings ("More", "#")Crt. Screen.send ("\ r \ n") Crt. Screen.readstring ("More", "#") # Send () sends a string to a remote device or screen, specifying the second parameter as Turecrt.Screen.Send ("Show version\r\n") when sending a string to the screen Crt. Screen.send ("\r\nhello,world!\r\n", True) Crt. Screen.ignorecase = Truewhile (Crt. Screen.waitforstring ("More", "Ten)"): Crt. Screen.send ("\ r \ n") # SendKeys () sends a button to the current window, including a combination of keys, such as the "Ctrl+alt+c" can be sent such as such a combination of keys, so write: Crt.screen.sendkeys ("^%c"); This feature requires the support of the language itself, currently only VBS and JS scripts can be used. # sendspecial () can send special control code, this control code is the CRT built-in function, specifically can contain the menu, Telnet, VT functions Feature List provides all the functions, CRT. Screen.sendspecial ("Vt_hold_screen") # Waitforcursor () waits for the cursor to move when the return value is true when there is a time-out parameter and the timeout returns false, otherwise it waits for the cursor to move. Using this function can be used to determine whether the output of a command is finished, CRT. Screen.waitforcursor (5) Crt. Screen.send ("\r\nhello,world!\r\n", True) if (Crt. Screen.waitforcursor (5)): CRT. Screen.send ("Show version\r\n") # Waitforkey () returns True when a keyboard key is detected, when there is a time-out parameter and the timeout returns false, otherwise it waits for the key if (CRT). Screen.waitforkey (5)): CRT. Screen.send ("Show version\r\n") # waitforstring () is typically used to send commands after waiting for a string # CRT. Screen.waitforstring (string,[timeout],[bcaseinsensitive]) Crt. Screen. Waitforstring ("#", "ten") # Waitforstrings () and waitforstring are the same features that can wait for multiple string output = Crt. Screen.waitforstrings (["Error", "Warning", "#"],10) index = CRT. Screen.matchindexif (index = = 0): Crt. Dialog.messagebox ("Timed out!") elif (index = = 1): CRT. Dialog.messagebox ("Found ' Error '") elif (index = = 2): CRT. Dialog.messagebox ("Found ' Warning '") elif (index = = 3): CRT. Dialog.messagebox ("Found ' #") # ReadString () is similar to the Waitforstrings feature, waiting for a few characters to appear, but it also reads all the characters that appear before the string. Crt. Screen.readstring ([string1,string2..],[timeout],[bcaseinsensitive]) 1, string, required parameter, waiting string, at least one, can be a special character such as: \r\n;2 , timeout, optional parameter, timeout, returns False when no corresponding string is detected, waits for no such parameter, 3, bcaseinsensitive, optional parameter, case insensitive, default value is False, indicates that the case of the string will be detected,    When True, the case is not detected.



This article goes from:

Http://www.cnblogs.com/zhaoyujiao/p/4908627.html

Python Scripting Learning Guide in SECURECRT

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.