Question

From the netcat man page one can sniff / save a TCP stream using something like:

mkfifo data
cat data | nc -l $port | tee -a $fn1 | nc $server $port | tee -a $fn2 > data

So I tried something like the following to do the same for UDP:

mkfifo data
cat data | nc -lu $port | tee -a $fn1 | nc -u $server $port | tee -a $fn2 > data

But it fails miserably, which I assume is because of the race conditions between writing to and reading from data and the pipe out of the tee command meaning I can't guarantee that UDP packets are transmitted one-by-one.

Is there an existing command or tool I can use to sniff UDP conversations without altering the packets? Preferably a 1-liner bash command, though a short ruby or python or whatever script works too.

Was it helpful?

Solution

socat -x "udp-listen:$port" "udp:$server:$host" 2> logfile
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top