如何向 telnet 提供文件

发布于 2024-08-28 17:05:26 字数 440 浏览 11 评论 0原文

试图理解 http 和标头,我正在使用 telnet 发送请求。为了不一次又一次地输入所有内容,我想我应该编写一个包含我需要的所有命令的小文本文件。

我的文件很简单,如下:

GET /somefile.php HTTP/1.1
Host: localhost

然后我尝试使用 io-redirection 将其提供给 telnet:

$ telnet localhost 80 < telnet.txt

但我得到的所有输出都是

Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

我做错了什么?

trying to understand http and headers i was playing around with telnet to send requests. to not type everything again and again and again i thought i'd write a small textfile with all the commands i need.

my file is as simple as follows:

GET /somefile.php HTTP/1.1
Host: localhost

i then try to feed it to telnet with io-redirection:

$ telnet localhost 80 < telnet.txt

but all output i get is

Trying ::1...
Connected to localhost.
Escape character is '^]'.
Connection closed by foreign host.

what am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

亚希 2024-09-04 17:05:27

telnet 不是适合这项工作的工具。尝试:

 netcat localhost 80 < telnet.txt

顺便说一句,如果您的计算机上没有安装该工具,您
可以在这里获取:

http://netcat.sourceforge.net/

telnet is not the right tool for this job. Try :

 netcat localhost 80 < telnet.txt

btw, if you don't have the tool installed on your machine, you
can get it here:

http://netcat.sourceforge.net/

空袭的梦i 2024-09-04 17:05:27

问题是您立即将所有输入提供给 telnet 命令,而无需等待其输出。在输入所有输入文件后,它会自动导致 telnet “挂起”,因为输入流到达其末尾 (EOF)。发生这种情况时,Telnet 可能仍处于实际等待与远程服务器建立连接的第一毫秒或微秒。
你想要做的是,发送一个命令到telnet,然后等待它完成它的工作,也就是等待服务器的响应,然后发送下一个命令,依此类推,只有当所有命令都结束时才挂断您发送的内容已实际处理。
为此,请使用“预期”脚本而不是即时输入文本文件。 “期望”是完成这项工作的常用工具。

The problem is that you feed all input to the telnet command instantly, without waiting for its output. Right after all of your input file has been fed, it will automatically cause telnet to "hang up", because the input stream reaches its end (EOF). Telnet might still be in its first millisecond or microsecond of actually waiting to establish a connection to the remote server when this happens.
What you want to do is, send a command to telnet, then wait for it to do its job aka wait for the server's response, then send the next command, and so on, and only hang up at the very end when all the commands you sent were actually processed.
To do this, use an 'expect' script instead of insta-feeding a text file. 'Expect' is the usual tool to do this job.

从﹋此江山别 2024-09-04 17:05:27

上面的建议非常好,只是用于 telnet 的端口号是 23,而不是 80。因此,如果您来这里寻找如何将数据输入 telnet 端口(就像我所做的那样,配置以太网控制的电源开关),那么请使用端口 23。

The advice above is pretty good, except the port number is 23, not 80, for telnet. So if you came here looking for how to feed data into a telnet port (as I did, to configure an ethernet-controlled power switch) then use port 23.

執念 2024-09-04 17:05:27

我不知道 telnet 是否可以实现这一点。你看过netcat吗?

I don't know if that's possible with telnet. Have you looked at netcat?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文