将原始数据发送到 TCP 服务器的 Linux 工具

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3010507/
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-08-03 20:07:26  来源:igfitidea点击:

Linux tool to send raw data to a TCP server

linuxtcp

提问by paul simmons

I am aware that this is not a direct 'development' question but I need this info to test a development project, so I think someone could've hit similar problem.

我知道这不是一个直接的“开发”问题,但我需要这些信息来测试一个开发项目,所以我认为有人可能会遇到类似的问题。

I will test a software that runs a TCP server and according to sent commands replies some answers. I will test the software and do not want to write code if it doesn't work well. So I want to send those commands and test drive the server software.

我将测试一个运行 TCP 服务器的软件,并根据发送的命令回复一些答案。我会测试软件,如果它不能很好地工作,我不想写代码。所以我想发送这些命令并测试驱动服务器软件。

How can I achieve this with a Linux box?

如何使用 Linux 机器实现这一目标?

采纳答案by luke

netcator telnet, i have used both in the past to test simple text based protocols. netcat is more flexible.

netcattelnet,我过去曾使用过这两种方法来测试基于简单文本的协议。netcat 更灵活。

回答by Brian Agnew

Sounds like Expectmay be what you want. There are implementations for multiple scripting languages, and you can script the requests/server responses plus appropriate timeouts, error handling etc.

听起来像Expect可能是您想要的。有多种脚本语言的实现,您可以编写请求/服务器响应以及适当的超时、错误处理等。

回答by Dummy00001

From bash with dd:

从 bash 使用 dd:

dd if=/dev/zero bs=9000 count=1000 > /dev/tcp/$target_host/$port

or even with cat:

甚至与猫:

cat < /dev/urandom > /dev/tcp/$target_host/$port