SecureCRT scripting

Simple example of a VBScript that will log you in to a Cisco router
# $language = “VBScript”
# $interface = “1.0”
This states that the script is synchronous with the screen
crt.Screen.Synchronous = True
This sends a Carriage Return to the screen
crt.Screen.Send vbCr
We now tell the script to wait until it sees ‘ssword:’
crt.Screen.WaitForString “ssword:”
Now that it sees that, send the characters VtYpAsS (vty password) and a carriage return
crt.Screen.Send “VtYpAsS” & vbCr
We now have to wait for the ‘>’ prompt
crt.Screen.WaitForString “>”
Now send out enable and a Carriage Return
crt.Screen.Send “enable” & vbCr
We now tell the script to wait until it sees ‘ssword:’
crt.Screen.WaitForString “ssword:”
Now that it sees that, send the characters LeVeL15 (enable password) and a carriage return
crt.Screen.Send “LeVeL15” & vbCr

Another simple script to show the ip interface status
# $language = “VBScript”
# $interface = “1.0”
crt.Screen.Synchronous = True
crt.Screen.Send vbCr
crt.Screen.WaitForString “#”
crt.Screen.Send “show ip int brief” & vbCr

Helpful Hints

Once your logged in via your scripts, set the line terminal length to 0 (IOS only)

objSc.WaitForString”#”,2
objSc.Send “terminal length 0” & vbCr 

If you don’t, you will have to WaitForString ”-” and then send a carriage return. With terminal length 0, the command will scroll through the entire list, never requiring a carriage return or space. At the very end, set your terminal length back to 80.
objSc.WaitForString”#”,2
objSc.Send “terminal length 80” & vbCr

For CatOS
objSc.WaitForString “)”
objSc.Send “set length 0” & vbCr
The set length 0 is for the current session only, so you will not have to set it back before the script ends.

Keyboard Mapping

I’ve found that it’s easiest to modify the ini file for the session. For example I want to use a specific keyboard mapping with a specific session. Why would I want this? I generally have three different keyboard mappings; one for CatOS, one for IOS, and for PixOS. I need to map the correct keyboard mapping to the correct device (so I get PixOS keyboard maps when I connect to a PIX). Here’s an example (from the ini file):

S:”Keymap Name”=Custom
S:”Keymap Filename”=C:crt scriptsPIX.key

Why use keyboard maps? Lets say your network has 100’s of routes and you more often than not only want to see a small range. In SecureCRT you can map a key (such as F6) to run a script. Create the script to type ‘show ip route | inc ”. Then map a key to the script, save the keyboard map (*.key) and load the keyboard map in the session (above). Now when your in your router, hit the key you just mapped and ‘show ip route | inc ‘ appears! Type in your network and hit enter. This is example is very basic, but you get the idea. I use mappings for logging, copy & paste, show ip route and some other commonly used commands.

Run from USB drive

A great tip from VanDyke is to run SecureCRT from a USB Drive. With this configuration you can run SecureCRT and have all your sessions in one easy place. I can go to any PC in the company and connect to my equipment. I can also go to my client sites and still use SecureCRT and use the above scripts and keyboard maps! Here’s the link on setting it up. http://www.vandyke.com/support/tips/usbdrive.html

Leave a Reply

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.