如何在不使用SendKeys的情况下自动化Telnet会话

6

我想telnet到我的路由器,并且我想自动化这个过程,以便我不必一直登录,因为我一天要做好几次。

除了VBS中的sendkeys之外,还有其他的方法吗?因为那会物理上敲打,所以telnet窗口需要处于活动状态,这相当烦人。

我尝试过批处理文件,但是得到了非常奇怪的结果。下面是批处理文件:

telnet 192.168.1.254
REM This is the router IP
ping 255.255.255.255 -n 1 -w 1000 > nul
REM This is to wait for the router if its being slow
George 
REM This is the username, as it prompts as soon as it logs in
ping 255.255.255.255 -n 1 -w 1000 > nul
(the password)
ping 255.255.255.255 -n 1 -w 1000 > nul
system
REM Enters the system menu
ping 255.255.255.255 -n 1 -w 10 > nul
debug
REM Enters the Debug menu
ping 255.255.255.255 -n 1 -w 100 > nul
:s
 cpu
 REM This lets me see the CPU usage
 ping 255.255.255.255 -n 1 -w 1000 > nul
 REM Wait while it lists it
 mem
 REM Checks the memory 
 ping 255.255.255.255 -n 1 -w 1000 > nul
 REM Waits again!
goto s
REM I need a loop otherwise I would have to type out lots of code!

以下是结果:
C:\Users\George\Desktop>telnet 192.168.1.254

C:\Users\George\Desktop>telnet 192.168.1.254
^C Terminate batch job (Y/N)?

为什么会出现这种情况?这应该是我预期的结果...
Username : George
Password : *******
------------------------------------------------------------------------

                             ______  Technicolor TG582n
                         ___/_____/\
                        /         /\\  8.C.M.0.AR
                  _____/__       /  \\
                _/       /\_____/___ \  Copyright (c) 1999-2012, Technicolor
               //       /  \       /\ \
       _______//_______/    \     / _\/______
      /      / \       \    /    / /        /\
   __/      /   \       \  /    / /        / _\__
  / /      /     \_______\/    / /        / /   /\
 /_/______/___________________/ /________/ /___/  \
 \ \      \    ___________    \ \        \ \   \  /
  \_\      \  /          /\    \ \        \ \___\/
     \      \/          /  \    \ \        \  /
      \_____/          /    \    \ \________\/
           /__________/      \    \  /
           \   _____  \      /_____\/
            \ /    /\  \    /___\/
             /____/  \  \  /
             \    \  /___\/
              \____\/

------------------------------------------------------------------------
{George}=>system
{George}=>debug
{George}[system debug]=>cpu
CPU (%):    Idle     User     Kernel
           57.43     0.99    41.58
{George}[system debug]=>mem
Total:                    61280 KB
Used:                     45216 KB
  by kernel:              30748 KB
  by applications:        14468 KB
{George}[system debug]=>

那么,为什么会出现这种情况呢?

除了 sendkeys 方法,我能使用其他方法吗?


你期望通过cmd.exe执行ping 255.255.255.255 -n 1 -w 1000 > nul,但是应该将“george”发送到telnet客户端?cmd.exe怎么知道你的期望呢? - jeb
哦,我之前用ping命令来创建延迟,因为连接需要一些时间。这就是为什么我会陷入无限循环吗? - George
3个回答

6
你可以搜索这个工具:它不是脚本化的Windows telnet.exe,而是一个可脚本化的telnet客户端。 Telnet Scripting Tool v.1.0
作者:Albert Yale

1
谢谢 - 我在这里找到了它(http://support.moonpoint.com/downloads/windows/network/Telnet/tst10.php),因为openDNS返回了您提供的链接错误。 - George

1

1
Telnet脚本工具(TST10)虽然老旧但非常高效,
这里有一个现代化的替代品,带有漂亮的GUI AutoTelnet.

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接