中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-14 13:10
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 如何实现用批处理输入特定字符并回车执行
楼 主 如何实现用批处理输入特定字符并回车执行 发表于 2009-02-18 00:22 ·  中国 安徽 合肥 电信
初级用户
★★
积分 122
发帖 54
注册 2006-11-03 04:24
UID 69380
性别 男
状态 离线
我现在有这样一个需求,如何来实现:
1. 用PING命令,PING IP,如果目标设备存在
2. 输入TELNET IP
3. 出现USER提示后:输入帐号
4. 出现PASSWORD后: 输入密码
5. 出现#号提示符后: 输入REBOOT
6. 循环第1步,直到IP地址为254为止
2 发表于 2009-02-19 00:52 ·  中国 北京 中国科学院研究生院玉泉四公寓
银牌会员
★★★
积分 1,187
发帖 555
注册 2006-12-21 07:35
UID 74129
性别 男
状态 离线
Originally posted by jasonwang at 2009-2-18 00:22:
我现在有这样一个需求,如何来实现:
1. 用PING命令,PING IP,如果目标设备存在
2. 输入TELNET IP
3. 出现USER提示后:输入帐号
4. 出现PASSWORD后: 输入 ...



@echo off

rem AutoTlnt.bat
rem Auto Detect and Telnet the remote machines, then reboot them
rem Version 1.0.0.0
rem Copyright 2009-2010 Scriptor (Scriptor@www.cn-dos.net)
rem Created at 23:28 2009年2月18日

rem ============================================================
rem Before you can go on, please read this REM carefully.
rem ~ stand for ENTER;
rem Modify the IP address you wana test;
rem Modify the Username and password to connect the remote machine.
rem NOTE: No Permission for Abusing of this script.
rem ============================================================

for /l %%a in (1,1,254) do (
ping -n 2 192.168.1.%%a|find /i "ttl" (
echo set sh=WScript.CreateObject("WScript.Shell") >tlnt%%a.vbs
echo WScript.Sleep 300 >>tlnt%%a.vbs
echo sh.SendKeys "open 192.168.1.%%a ~" >>tlnt%%a.vbs
echo WScript.Sleep 500 >>tlnt%%a.vbs
echo sh.SendKeys "Username ~" >>tlnt%%a.vbs
echo WScript.Sleep 400 >>tlnt%%a.vbs
echo sh.SendKeys "Password ~">>tlnt%%a.vbs
echo WScript.Sleep 500 >>tlnt%%a.vbs
echo sh.SendKeys "reboot ~">>tlnt%%a.vbs
start telnet
cscript //nologo tlnt%%a.vbs
del tlnt%%a.vbs
)
)
论坛跳转: