Telnet programming Telnet automatic logon to routers, switches, and other network devices batch processing

Source: Internet
Author: User
Tags switches

@echo off Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs Echo Wscript.Sleep >>telnet_ Tmp.vbs echo Sh. SendKeys "Open your network device telnet login IP" >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys "your username {ENTER}" >>telnet_tmp.vbs echo Wscript.Sleep >>telnet_tmp.vbs echo Sh. SendKeys "Your password {ENTER}" >>telnet_tmp.vbs start Telnet cscript//nologo telnet_tmp.vbs del telnet_tmp.vbs

Explain:
This code Wscript.Sleep 300 indicates that the login device is delayed, which is to give the device a time to accept; Open is to turn on Telnet and log on to the specified IP address; {Enter} is a carriage return; SendKeys is the key, the content that is automatically entered. Save the above content for Rout.bat batch file, each log on network equipment do not first win+r-cmd-telnet IP-user name-password so troublesome, directly run this bat file to the login status. Of course, if you want to log in to other states, such as the Conf configuration status, you can also add a few lines after the password, such as:

@echo off Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs Echo Wscript.Sleep >>telnet_ Tmp.vbs echo Sh. SendKeys "Open your network device telnet login IP" >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys "your username {ENTER}" >>telnet_tmp.vbs echo Wscript.Sleep >>telnet_tmp.vbs echo Sh. SendKeys "Your password {ENTER}" >>telnet_tmp.vbs echo Wscript.Sleep >>telnet_tmp.vbs echo Sh. SendKeys "Conf{enter}" >>telnet_tmp.vbs start Telnet cscript//nologo telnet_tmp.vbs del telnet_tmp.vbs

If your device does not authenticate user name, as long as the password, remove the user name entered the line:

@echo off Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs Echo Wscript.Sleep >>telnet_ Tmp.vbs echo Sh. SendKeys "Open your network device telnet login IP" >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys ' {ENTER} ' >>telnet_tmp.vbs echo wscript.sleep >>telnet_tmp.vbs echo Sh. SendKeys "Your password {ENTER}" >>telnet_tmp.vbs start Telnet cscript//nologo telnet_tmp.vbs del telnet_tmp.vbs

Some switches require more waiting time after input, and can add a few lines of Echo Wscript.Sleep >>telnet_tmp.vbs to the device buffering delay as appropriate.

"Supplement"

Each key is represented by one or more characters. To specify a single keyboard character, use the character itself. For example, to represent the letter A, pass the string "a" to the method. To represent more than one character, append each additional character to the character before it. To represent letters A, B, and C, specify the parameter as "ABC".

The plus sign (+), caret (^), percent sign (%), wave number (~), and parentheses () have special meanings for SendKeys. To specify a character in these characters, enclose it in braces ({}). For example, to specify a plus sign, use "{+}". To specify curly braces characters, use ' {{} ' and ' {}} '. Brackets ([]) have no special meaning for SendKeys, but they must be enclosed in curly braces.

To specify a character that does not appear when you press a key, such as Enter or TAB, and a key that represents an action but does not represent a character, use the code in the following table:

Key

Code

Backspace

{BACKSPACE}, {BS}, or {BKSP}

Break

{Break}

Caps Lock

{CapsLock}

Del or Delete

{DELETE} or {DEL}

Down ARROW

{Down}

End

{End}

Enter

{ENTER} or ~

Esc

{ESC}

Help

{Help}

Home

{Home}

Ins or Inserts

{INSERT} or {INS}

Left Arrow

{left}

Num Lock

{NumLock}

Page down

{PGDN}

Page up

{PgUp}

Print screen

{PRTSC} (reserved for future use)

Right Arrow

{Right}

Scroll Lock

{ScrollLock}

Tab

{TAB}

Up ARROW

{Up}

F1

{F1}

F2

{F2}

F3

{F3}

F4

{F4}

F5

{F5}

F6

{F6}

F7

{F7}

F8

{F8}

F9

{F9}

F10

{F10}

F11

{F11}

F12

{F12}

F13

{F13}

F14

{F14}

F15

{F15}

F16

{F16}

Numeric keypad Plus

{ADD}

Numeric keypad minus sign

{Subtract}

Digital keypad multiplication

{MULTIPLY}

Digital keypad Division

{DIVIDE}

To specify the keys to use with any combination of the shift, Ctrl, and ALT keys, precede the key codes with a paragraph or more of the following code.

Key

Code

Shift

+

Ctrl

^

Alt

%

To specify that you hold down the Shift, Ctrl, and Alt key combinations when you press some keys, enclose the code for those keys in parentheses. For example, to specify that you hold down the Shift key while pressing E and C, use the + (EC). To specify that you should hold down SHIFT while pressing E, and then press C without holding down SHIFT, use +EC.

To specify a duplicate key, use the format {key number}. A space must be placed between the key and the number. For example, {left 42} means 42 times, and {h 10} means 10 times per h.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.