Many of my friends asked me how to set automatic logon to telnet. Here we will introduce this operation. There are two platforms: Windows and Linux. We will introduce the process of automatic logon to telnet on both platforms. Hope to help you.
Automatic logon to telnet batch files
I. Automatic logon to telnet on Windows:
Copy the code to notepad and save it as autoTelnet. bat. Then, double-click it to automatically log on to the telnet server and modify the Server IP address.
- @echo off
- echo set sh=WScript.CreateObject("WScript.Shell") >telnet_tmp.vbs
- echo WScript.Sleep 300 >>telnet_tmp.vbs
- echo sh.SendKeys "open 192.168.1.200" >>telnet_tmp.vbs
- echo WScript.Sleep 300 >>telnet_tmp.vbs
- echo sh.SendKeys "{ENTER}" >>telnet_tmp.vbs
- echo WScript.Sleep 300 >>telnet_tmp.vbs
- echo sh.SendKeys "engineer{ENTER}" >>telnet_tmp.vbs
- echo WScript.Sleep 300 >>telnet_tmp.vbs
- echo sh.SendKeys "ls {ENTER}">>telnet_tmp.vbs
- start telnet
- cscript //nologo telnet_tmp.vbs
- del telnet_tmp.vbs
Appendix:
For what the SendKeys command can send, we can look at the following list:
- 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 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 %
II. Automatic logon to telnet on Linux
Make sure that your system has an executable program, save the following code to the file autoTelnet, and grant the execution permission. Detailed operation view command audit CT
- #!/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