Question

I'm trying to send a bunch of commands to an IP camera using Netcat. My problem is sending more than one command. This works fine:

echo get_video_state | nc -u -i 1 -w 5 192.168.xxx.xx 60000

And returns the expected value "is_stopped"

However, when I try several commands like so:

echo get_video_state | echo get_resolution | nc -u -i 1 -w 5 192.168.xxx.xx 60000

I expect first the 'get_video_state' parameter to be sent, followed by a delay of 1 second (because of the -i 1), and then the -get_resolution'. However, only the resolution is returned.

Does anyone have any experience with this?

Was it helpful?

Solution

The pipe ("|") redirects the output of one command to the input of another command, so echo get_video_state | echo get_resolution | nc -u -i 1 -w 5 192.168.xxx.xx 60000 wont work, because output of first echo is redirected to the second echo. You have to run the commands separately and then redirect their output to netcat. You can do this in this way:

(echo get_video_state & echo get_resolution) | nc -u -i 1 -w 5 192.168.xxx.xx 60000
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top