Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ SecureCRT in Python scripting study guide     - Linux RHCS basic maintenance commands (Linux)

- Check with Hello World Docker installation (Server)

- Install Python 3.3.4 under CentOS 6.4 (Linux)

- Command-line based tools for better alternatives (Linux)

- Programmer editor Vim (Linux)

- CentOS 7.0 running Docker kernel error solution (Server)

- Inject script commands manually annotated summary (Linux)

- SQL statement to repair SQL Server database (Database)

- Python console achieve progress bar (Programming)

- Install Git on CentOS (Linux)

- MySQL separation Amoeba achieve literacy (Database)

- MySQL IO SSD attempt at optimization (Database)

- Android custom controls create the simplest skid menu in the history (Programming)

- Use Visual Studio Code Development TypeScript (Linux)

- Caffe install under Ubuntu 14.04 64bit (Linux)

- Apache POI Excel Document Processing (Linux)

- APT-mirror using a four-step configuration Ubuntu local depot (Linux)

- Oracle RMAN-06023 and ORA-19693 errors (Database)

- Linux 0.12 kernel and modern kernels difference in memory management (Linux)

- An Example of GoldenGate Extract Process Hang Problem Solving (Database)

  SecureCRT in Python scripting study guide
  Add Date : 2018-11-21      

In the test network equipment is generally used for device-side scripts for configuration and testing, and maintenance; maintenance personnel to test for PE equipment is used frequently SecureCRT tool; SecureCRT supports VB, JavaScript, Python and other scripting languages, in order to achieve script richer stably performed in a CRT, CRT master common functions are very useful. The next time I will SecureCRT commonly used functions scripting expand learning applications.


(1) using the python language SecureCRT in Dialog functions

# $ Language = "Python"
# $ Interface = "1.0"

# Crt.Dialog.FileOpenDialog ([title, [buttonLabel, [defaultFilename, [filter]]]])
# Pop up a dialog box to select a single file; If you select a specific file returns the absolute path to the file, if you select the pop of "Cancel", then return 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, buttons and text messages, and simple dialogue to achieve a user;
crt.Dialog.MessageBox (filePath, "", 64 | 0)
crt.Dialog.MessageBox ( "Session disconnected", "session", 64 | 2)
crt.Dialog.MessageBox ( "confirm exit", "session", 32 | 1)
crt.Dialog.MessageBox ( "confirm exit", "session", 32 | 3)
crt.Dialog.MessageBox ( "whether to continue with the installation", "session", 32 | 4)
crt.Dialog.MessageBox ( "This session is open", "session", 48 | 5)
crt.Dialog.MessageBox ( "Unable to connect this window", "session", 16 | 6)

# Crt.Dialog.Prompt (message [, title [, default [, isPassword]]])
# Pops up an input box, the user can fill in the text, for example, fill in the file name, fill in the path, fill in the IP address, operating results if you click 'ok', returns the input string, otherwise it 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 SecureCRT features of Screen

# $ Language = "Python"
# $ Interface = "1.0"

# CurrentColumn returns the column coordinates of the current cursor.
curCol = crt.Screen.CurrentColumn
crt.Dialog.MessageBox (str (curCol))

# CurrentRow Back row coordinates of the current cursor.
curRow = crt.Screen.CurrentRow
crt.Dialog.MessageBox (str (curRow))

# Columns Returns the current maximum column width of the screen
cols = crt.Screen.Columns
crt.Dialog.MessageBox (str (cols))

# Rows Returns the current maximum line width of the screen
rows = crt.Screen.Rows
crt.Dialog.MessageBox (str (rows))

Whether to acquire Escape character #IgnoreEscape defined when using WaitForString, WaitForStrings and ReadString these three methods (special characters such as carriage return) will get the default
crt.Screen.IgnoreEscape = False
crt.Dialog.MessageBox (crt.Screen.ReadString ([ "\ 03"], 5)) # Get ctrl + c

crt.Screen.IgnoreEscape = True
crt.Dialog.MessageBox (crt.Screen.ReadString ([ "\ 03"], 2)) # not get ctrl + c

# MatchIndex definitions capture the return value when using WaitForStrings and ReadString these three methods based on positional parameters, calculated from the 1 start, if there is no match 0 is returned.
outPut = crt.Screen.ReadString ([ "error", "warning", "#"], 10)
index = crt.Screen.MatchIndex
if (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 synchronization properties Setting screen. If set to false, it is used in scripts WaitForString, WaitForStrings, there may be some loss of data phenomenon ReadString function, the setting of the screen might exist after Caton is true, the default is false
crt.Screen.Synchronous = True
crt.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 () in accordance with the coordinates taken on the character of a rectangle of the screen (ie starting with a column in a row to other rows other columns), does not contain the string carriage return, so this is used to obtain more unformatted cursor string, or a string of small pieces of a specific area.
out = crt.Screen.Get (row1, col1, row2, col2)
crt.Dialog.MessageBox (out)

# Get2 () Remove the interpretation of a character on the screen according to the rectangle coordinates (ie starting with a column in a row to other rows other columns) that contains the string carriage return, so this is used to obtain more large sections of the belt string format.
crt.Screen.Get2 (row1, col1, row2, col2)

# IgnoreCase using the global control parameter settings when using WaitForString, WaitForStrings and ReadString if these three functions are case-sensitive, sensitive string defaults to false checks, set to true then the case will not be detected.
crt.Screen.IgnoreCase = True
crt.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 () to send a string to the remote device or screen, you need to specify the second parameter when sending a string to the screen as Ture
crt.Screen.Send ( "show version \ r \ n")
crt.Screen.Send ( "\ r \ nhello, world! \ r \ n", True)
crt.Screen.IgnoreCase = True
while (crt.Screen.WaitForString ( "more", 10)):
    crt.Screen.Send ( "\ r \ n")

# SendKeys () button to send the current window, comprising a combination of keys, for example, can send a similar "CTRL + ALT + C" and other such key combinations, you can write: crt.screen.sendkeys ( "^% c"); this language functions required to support itself, only VBS and JS scripts can be used.

# SendSpecial () can send a special control code, the control code is Crt built-in functionality specifically have included all the features of Menu, Telnet, VT functions function provided in the list,
crt.Screen.SendSpecial ( "vT_HOLD_SCREEN")

# WaitForCursor () wait for cursor movement, the return value is true when moving, when a timeout timeout parameters and returns false, otherwise it will wait until the cursor moves. Using this feature can be used to determine whether the output end of a command,
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 detection when keyboard keys, when a timeout timeout parameters and returns false, otherwise it will have to wait buttons
if (crt.Screen.WaitForKey (5)):
    crt.Screen.Send ( "show version \ r \ n")

# WaitForString () is generally used to send a command string to wait
# Crt.Screen.WaitForString (string, [timeout], [bCaseInsensitive])
crt.Screen.WaitForString ( "#", 10)

# WaitForStrings () and WaitForString is the same function, multiple strings can wait
outPut = crt.Screen.WaitForStrings ([ "error", "warning", "#"], 10)
index = crt.Screen.MatchIndex
if (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 () function is similar to WaitForStrings are waiting for a few characters appear, except that all the characters appear before it will read the string.
crt.Screen.ReadString ([string1, string2 ..], [timeout], [bCaseInsensitive])
1, string, required parameter string to wait, at least one can be special characters such as: \ r \ n;
2, timeout, optional parameter timeout is not detected when the corresponding string will return false, will not have to wait when this parameter;
3, bCaseInsensitive, optional parameter is not case sensitive, the default value is false, indicating that the detected string case, when the detection of the case is not true.
- Use $ BASH ENV variable to mention the right way under Linux (Linux)
- Customize the 404 error page Nginx (Server)
- Oracle Linux 5.5 (64bit) Install Oracle 11gR2 RAC detailed tutorial (Database)
- Linux and Unix systems really do network more secure (Linux)
- Linux installation skynet issue summary (Linux)
- awk variables (Linux)
- A deep understanding of Java enum (Programming)
- Bash job control (Linux)
- Linux system security settings after installation (Linux)
- Intrusion analysis and prevention tools Knark under Linux platform (Linux)
- Oracle create a temporary table space group (Database)
- How to migrate MySQL to MariaDB under linux (Database)
- Linux kernel netpoll framework netconsole (Linux)
- Linux system installation and usage instructions Wetty (Linux)
- LNMP Note: Addressing mail function can not send mail (Server)
- Use smem visual display Linux memory usage (Linux)
- CentOS5 installation Nodejs (Linux)
- Why HBase need to build SQL engine layer (Database)
- Quota for Vsftpd do use disk quotas (Server)
- How to install Linux Kernel 4.4 on Ubuntu (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.