Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question
    
Do you have a firewall? Seeing the packet via tcpdump doesn't mean that it will be accepted. –  Zoredache Apr 3 '10 at 1:07
add comment

1 Answer

up vote 1 down vote accepted

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

share|improve this answer
    
Hello and thanks for your reply. The command sequence the way you wrote it exits right after its' execution on my machine. However the problem is solved for me. I didn't know I could just run nc -u 1.1.1.1 9999, and send/receive data inside nc while its running. Thanks a lot once again –  user39593 Apr 3 '10 at 1:12
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.