How to get a udp response with netcat

netcat

I am trying to do something like:

echo "request" | nc -u 1.1.1.1 9999 > response.txt

I can see that response is coming from server (with tcpdump) after executing this line.

However, my response.txt stays empty.

Is there a way to get it?

Best Answer

Netcat starts "talking" UDP (default is TCP) by specifying the -u command line option. Here's an example of connecting to an RFC 867 time server using UDP. Note the IP address or DNS name of the other host is specified first and the port number is specified second - just like most telnet programs. After the connection is made you'll probably need to press the Enter key to get the time server to send you the current time. (maybe this is your problem)

nc -u igor.alcpress.com 13

Thu Sep 15 14:41:57 2005

Since UDP is not a connection-oriented protocol, the connection will remain "open" until you terminate the program by pressing Ctrl-C.

======================================================================

Does it reply if you don't redirect output ?
try : echo "request" | nc -u 1.1.1.1 9999 | tee response.txt