Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ SecureCRT in Python scripting study guide     - Haproxy multi-domain certificate HTTPS (Server)

- ssh port forwarding Comments (Server)

- Linux RPM default installation path (Linux)

- Oracle 10g after the failure to start the upgrade (Oracle instance terminated. Disconnection forced) (Database)

- Linux kernel socket protocol stack routing lookup cache mechanism (Linux)

- Fatal: unable to connect to github.com problem solving (Linux)

- Java threads in the life cycle (Programming)

- Linux how to view your JDK installation (Linux)

- The method of installing software under Ubuntu Linux (Linux)

- How to implement Linux host Telnet SSH password Free (Server)

- After the first remote installation GlassFish Web to remotely access their back office management system error solution appears (Server)

- How to make Linux a non-root user uses less than 1024 ports (Linux)

- CentOS6.6 ordinary users to use sudo command to borrow root user privileges (Linux)

- Production Environment MongoDB Fragmentation and Cluster Solution (Database)

- Each catalog Detailed Linux (Linux)

- C ++ input and output summary _ Input (Programming)

- Linux filtration empty file command summary (Linux)

- Ubuntu deploying Solr (4.4) to Tomcat (7.0.53) (Server)

- Create a custom pixel format based on an existing image data BufferedImage (Programming)

- JVM garbage collector and memory allocation strategy (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:      
 
- Mount NFS network file system (Linux)
- Linux system started to learn: the Linux syslog (Linux)
- Ubuntu 12.04 LTS installation configuration JDK1.6.0_45 (Linux)
- Python basis: os module on the file / directory using methods commonly used functions (Programming)
- Recover accidentally deleted Nginx logs (Server)
- Talk about the Linux folder permissions issue again (Linux)
- 14 useful example Linux Sort command (Linux)
- Timeout control related to Python threads and a simple application (Programming)
- Some practical tips Linux (Linux)
- phpinfo (): like phpinfo as a Python script (Programming)
- Linux common commands ll namely ls -l --color = auto (Linux)
- Set multiple IP addresses for a single network card on Ubuntu 15.10 (Linux)
- Linux install Maven and SVN client (Linux)
- Unable to start the network after restart clone a virtual machine (Linux)
- MySQL management partition table (Database)
- Python cause yum upgrade error (Linux)
- Linux iostat command example explanation (Linux)
- Linux Mint 17 set up the Ruby environment (Linux)
- JavaScript common array manipulation functions and usage (Programming)
- Elaborate .NET Multithreading: Concepts (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.