Automatic logon to Telnet batch file
One. Windows platform:
Copy the code into Notepad and save it as Autotelnet.bat, then double-click Run to automatically log on to the Telnet server, the server IP to modify itself
@echo off
Echo Set Sh=wscript.createobject ("Wscript.Shell") >telnet_tmp.vbs
Echo Wscript.Sleep >>telnet_tmp.vbs
Echo Sh. SendKeys "Open 192.168.1.200" >>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 "Engineer{enter}" >>telnet_tmp.vbs
Echo Wscript.Sleep >>telnet_tmp.vbs
Echo Sh. SendKeys "ls {ENTER}" >>telnet_tmp.vbs
Start Telnet
cscript//nologo Telnet_tmp.vbs
Del Telnet_tmp.vbsAppendix:for SendKeys This command can send what, we can look at the following list:BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
Break {Break}
CAPS LOCK {CAPSLOCK}
del or DELETE {delete} or {DEL}
ARROW {down}
End {END}
ENTER {enter}or ~
ESC {ESC}
Help {Help}
Home {Home}
INS or insert {Insert} or {INS}
Left ARROW {left}
NUM LOCK {NumLock}
PAGE Down {PGDN}
PAGE up {PgUp}
PRINT Screen {PRTSC}
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}SHIFT +
CTRL ^
ALT%two. Linux platforms
ensure that your system exists expect this executable program, save the following code to the file autotelnet, and give the Execute permission. Detailed Operation view command expect#!/usr/bin/expect--
Set SERVER "192.168.1"
Set USER "MyUserName"
Set PASSWD "Mypass"
If {$ARGC} {
Spawn telnet $SERVER. $argv
} else {
Spawn Telnet $SERVER. 200
}
Expect "Password:"
Send "$PASSWD \ n"
Expect "#"
Send "ls\n"
Interact
Automatic logon to Telnet batch file