开发者

Writing output from a socket

开发者 https://www.devze.com 2023-01-17 06:59 出处:网络
I have 2 machines A and B. In开发者_StackOverflow中文版 machine A, I do echo \"Hello World\" > /dev/tcp/{Bs_ip}/12345

I have 2 machines A and B.

In开发者_StackOverflow中文版 machine A, I do

echo "Hello World" > /dev/tcp/{Bs_ip}/12345

In machine B, how do I write a script that runs in the background, listens on port 12345, and prints whatever it receives from port 12345 to stdout?

BTW both machines are running Red Hat Enterprise Linux AS 4.

Thanks


You can do that using netcat:

nc -l -p 123456

If you want to be able to handle multiple connections you will have to use a loop.


You can use netcact (nc) or netcat on steroids, ie socat. I gave a link to the examples section of the man page, so that you can see how powerful socat is.

socat TCP4-LISTEN:12345 - 

Should do what you want

0

精彩评论

暂无评论...
验证码 换一张
取 消