windows telnet 输出使用 .bat 文件将其保存到文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20970530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 11:14:00  来源:igfitidea点击:

telnet output save it to file using .bat file

windowsshelltelnet

提问by user3095838

telnet 10.0.0.22 3389 ( for checking rdp port ) I want to create a batch file, for checking two or three port, so i create a .bat file in that i have written

telnet 10.0.0.22 3389(用于检查 rdp 端口​​)我想创建一个批处理文件,用于检查两个或三个端口,所以我创建了一个 .bat 文件,我已经写了

telnet 10.0.0.22 1158 >> C:\result\telnetresult.txt
telnet 10.0.0.22 3389 >> C:\result\telnetresult.txt
telnet 10.0.0.22 1159 >> C:\result\telnetresult.txt

but it didn't work. Can you suggest where i am doing mistake or if there is some other alternative / Workaround. I also tried to create another .bat file with the following command. Telnet set logfile c:\log.txt

但它没有用。您能否建议我在哪里做错了,或者是否有其他替代方案/解决方法。我还尝试使用以下命令创建另一个 .bat 文件。Telnet 设置日志文件 c:\log.txt

Open 10.0.0.22 80
open 10.0.0.22 1158
open 10.0.0.22 3389

but it also didn't work.

但它也没有用。

回答by Isak

You could try telnet “IP Address” -f “file location". Found the solution here.

你可以试试telnet “IP Address” -f “file location"。在这里找到了解决方案。

回答by BMW

try this:

尝试这个:

for port in 1158 3389 1159 
do
  echo "telnet 10.0.0.22  $port"
  echo $port |xargs telnet 10.0.0.22  >> C:\result\telnetresult.txt
done

some similar output

一些类似的输出

telnet 10.0.0.22 1158
Trying 10.0.0.22...
telnet: Unable to connect to remote host: Connection refused
telnet 10.0.0.22  3389
Trying 10.0.0.22...
telnet: Unable to connect to remote host: Connection refused
telnet 10.0.0.22  1159
Trying 10.0.0.22...
Connected to 10.0.0.22.
Escape character is '^]'.
Connection closed by foreign host.