Linux tool to send raw data to a TCP server

2019-03-08 23:30发布

问题:

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.

How can I achieve this with a Linux box?

回答1:

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



回答2:

From bash with 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


回答3:

Sounds like Expect may 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.



标签: linux tcp