Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ SecureCRT in Python scripting study guide     - How to display a dialog Bash Shell script (Programming)

- There is sort of a directed acyclic graph topology (Programming)

- To create a full command line Android Build System (Linux)

- How to defragment the hard disk in Linux (Linux)

- shell script: MySQL monitoring service is normal (Database)

- EXP-00091 Error resolved (Database)

- How to Install Focuswriter 1.4.5 (Linux)

- Ubuntu 14.04 Install WordPress on Nginx (Server)

- Shell script to crawl through AWR SQL Report Problems (Database)

- Nginx version of helloworld (Server)

- After Ubuntu Password Forgot your way back (Linux)

- Android Get App version number and version name (Programming)

- High-performance JavaScript DOM programming (Programming)

- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)

- HTML5 Application Cache (Programming)

- How to Set Free SSH password on CentOS / RHEL (Linux)

- Three details reflect the Unix system security (Linux)

- Is Linux the most secure operating system (Linux)

- Linux server is how to do after the invasion (Linux)

- Nodejs mysql pool Example (Programming)

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

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.

content

(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.
     
         
         
         
  More:      
 
- Oracle 11g RMAN virtual private directory (Database)
- OpenWRT environment to build (Linux)
- Linux print file and send mail (Linux)
- Stucts2 values on the page and how the attribute values corresponding to the Action (Programming)
- Ubuntu rights management common commands (Linux)
- Android Studio simple setup (Linux)
- Oracle RAC 10.2.0.5 upgrade to 11.2.0.4 problems encountered (Database)
- Linux automatic installation and implementation (Linux)
- Linux Shell introduces (Linux)
- CentOS 6.5 can not connect to the network under VMware (Linux)
- C language Bubble Sort - integer sort (Programming)
- CentOS 6.4 of cron scheduled task configuration (Linux)
- MySQL main and backup replication structures (using mysqld_multi) (Database)
- 10 useful Linux command line tips (Linux)
- Asynchronous communication mechanism between the Android source code analysis thread (Programming)
- Log4cplus logging facility configuration, installation, testing (Linux)
- Ubuntu How to install and upgrade Linux Kernel 3.15 (Linux)
- About ORA-02391 solution (Database)
- Nmcli based network management command-line tool (Linux)
- Install Firefox 32 official version of the Linux system (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.