Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ SecureCRT in Python scripting study guide     - Linux (CentOS) SSH login without password authentication (Linux)

- rpm package specify the installation path (Linux)

- Ubuntu 15.04 Linux install anti-virus software Antiviral 0.2 (Linux)

- Syncthing: Private Security Synchronization tool to synchronize files between computers / folder (Linux)

- To install the Git and Github under Ubuntu (Linux)

- Android judgment toward camera pictures (Programming)

- iOS GCD multithreading simple to use (Programming)

- Talk about Java EE Learning (Programming)

- CentOS iptables firewall configuration (Linux)

- Ubuntu install perfectly handsome terminal Guake 0.8.1 (Linux)

- Linux SSH remote connection service slow Solutions (Linux)

- Java proxy mode (Programming)

- Hadoop 2.6.0 stand-alone / pseudo-distributed installation (Server)

- To compile install and test Swift under Linux (Linux)

- The security configuration of Linux (Linux)

- In-depth understanding of PHP ini configuration (Server)

- A brief description of Java 8 new features introduced syntax (Programming)

- CentOS7 installation GAMIT and GMT (Linux)

- exp / imp Export Import version of the problem and the ORA-6550 error (Database)

- C ++ Object Model Comments (Programming)

  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.
- To configure Samba to share files with Windows under CentOS (Linux)
- Getting Started with Linux: Learn how to install and access CentOS 7 Remote Desktop on a VPS (Server)
- JSON data normalization (normalize) (Programming)
- After installing minimize RHEL / CentOS 7 we need to do (Linux)
- Graphical interface for the CentOS 6.4 installed and connected by remote VNC (Linux)
- To resolve Ubuntu 14.04 Unity Desktop Environment Login freeze problem (Linux)
- Service manager OpenBSD on rccl (Server)
- Comparison of one-time transaction and CTE insert data (Database)
- To protect the temporary files for Linux security (Linux)
- GO five stages of language learning (Programming)
- Scope of variables in C # (Programming)
- Java regular expression syntax (Programming)
- Intruder tools Knark Analysis and Prevention Linux environment (Linux)
- C language binary tree (Programming)
- Nginx is used to build the cache module srcache_nginx (Server)
- Use OpenSSL to generate a certificate detailed process (Linux)
- ElasticSearch - Basic Concepts (Server)
- How to Install lightweight Budgie desktop on Ubuntu 14.04 (v8) (Linux)
- PHP interview questions of design patterns (Programming)
- PLSQL Developer synchronization table tools (Database)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.