Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ SecureCRT in Python scripting study guide     - MySQL how to export files with the date format (Database)

- MySQL separation Amoeba achieve literacy (Database)

- Oracle ORA-01089 failure analysis (Database)

- How Datadog monitor Nginx (Server)

- Java thread pool: ExecutorService, Executors (Programming)

- Mount and unloading disks under Linux (Linux)

- Linux system performance and usage activity monitoring tools -Sysstat (Linux)

- RAID configuration and management under linux (Server)

- SELinux security permissions HTTP + PHP service changes (Server)

- Taught you how to build your own VPS server (Server)

- SteamOS installation under Ubuntu 14.04 (Linux)

- Installation and Configuration rsync server under CentOS 6.3 (Server)

- How to forcibly change the Linux system password on a regular basis (Linux)

- Oracle 10g New Features - Archive Compression (Database)

- Ubuntu dual-card system configuration method (Server)

- Dell R710 server disk recovery database one case (record) (Server)

- Troubleshooting Linux virtual machine device id and the letter of inconsistencies (Linux)

- Monitor log file (listener.log) (Database)

- See Linux kernel, CPU, memory, and various versions of the command module and means (Linux)

- Inherent limitations of Linux systems network security (Linux)

  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.
- Getting Started with Linux system to learn: How do I know which processes are running on the CPU core (Linux)
- CentOS system Amoeba + MySQL Master-slave configuration (Database)
- How to Install Winusb in Ubuntu 14.04 (Linux)
- exp / imp Export Import version of the problem and the ORA-6550 error (Database)
- How to Use Nmap security scanner tool on Linux (Linux)
- Oracle 11G using DG Broker create DataGuard (Database)
- Install the latest Eclipse IDE in Ubuntu (Linux)
- Analysis of native Java keywords (Programming)
- CentOS 6.x Basic System Optimization after installation (Linux)
- Linux system Iptables Firewall User Manual (Linux)
- Parameters of the extra port MySQL 5.6 (Database)
- CentOS Linux firewall configuration and Close (Linux)
- GitLab remote backup of Linux Shell Scripting (Linux)
- Linux print file and send mail (Linux)
- HDFS Hadoop Distributed File System Works (Server)
- Eight kinds of techniques to solve hard problems Linux (Linux)
- Nginx caching using the official guide (Server)
- Network Security: SYN attacks against under linux (Linux)
- Use PuTTY key authentication mechanism for remote login Linux (Linux)
- Workaround CentOS error message during compilation PHP5 common (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.