1

我想编写 telnet 脚本来测试我的网站输入处理。我可以手动完成:

telnet localhost 8888
...
GET / HTTP/1.1\n
Host: localhost


...html response

但是我可以在我的 shell 脚本中将命令传递给 telnet !

我试过了 :

(echo "GET / HTTP/1.1\n"; echo "Host: localhost \n\n"; sleep 1) | telnet localhost 8888

它根本不会产生任何结果!

4

3 回答 3

3

我发现netcatakanc更适合此类任务。

此外,正如 Giuseppe 提到的,您必须修复引用。另一种方法bash -e是引用 using $'this form',其中\n,\tbash在解析命令行时被解释而不是传递给echo. 因此,该形式适用于许多不同的实用程序。

于 2010-03-24T17:02:03.250 回答
2

(可能不是唯一的问题)您应该“echo -en”,并使用单引号来关闭字符串。这使得 bash 正确解释 \n

问候

于 2010-03-24T16:54:00.897 回答
1

“我如何编写 x 脚本?”的通常答案。是“ expect

于 2010-03-24T18:46:07.713 回答