自动登录telnet批处理文件_休闲 自动登录telnet批处理文件
2008-05-29 09:26:38
版权声明:原创作品,如需转载,请与作者联系。否则将追究法律责任。
自动登录telnet批处理文件
一。Windows平台:
复制一下代码到记事本中并另保存为autoTelnet.bat,之后双击运行就实现自动登录到telnet服务器了,服务器IP自己修改
@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
附录:
对于SendKeys这个命令可以send什么,我们可以看下面的列表:
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 %
二。Linux平台

保证你的系统上存在expect这个可执行程序,保存以下代码到文件autoTelnet,并给与执行权限。详细操作察看命令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