Tuesday, March 15, 2022

[SOLVED] How to send stdout of one Python program over UDP to stdin of another using BASH?

Issue

I'm running foo.py on Ubuntu box A, and I want to feed its stdout as stdin to bar.py running on Ubuntu box B.

I think python foo.py | /dev/udp/12.34.56.78:1234 will send out of box A to box B, but how can I pick up the packets and feed them into bar.py?

I need something like udp_listener localhost:1234 | bar.py but (if that's correct) what's the actual syntax?


Solution

On your Ubuntu box B, run

nc -klu -p 1234 | cat

On your Ubuntu box A, run

echo "Hello world" > /dev/udp/12.34.56.78/1234

If this works, replace cat with bar.py and replace echo "Hello world" with python foo.py

You may need to open firewall for boxB:1234/udp



Answered By - Philippe
Answer Checked By - Willingham (WPSolving Volunteer)