Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there a way to make netcat receive UDP packets from any ip:port? I don't want it to bind to a specific host as the first packet comes.

I can consider alternatives, but they have to be bash friendly (allow piping).

share|improve this question
    
what are you trying to achieve? –  Lucas Kauffman Jul 14 '12 at 20:05
    
@LucasKauffman just dump whatever udp packet arrives to a specific port. I cannot use tcpdump as I don't have root privileges on the machine. –  Lorenzo Pistone Jul 15 '12 at 11:37
add comment

3 Answers

If you you are doing this on Linux then you could set up an iptables rule using the REDIR target. Just redirect all UDP traffic to a single port and then listen on that port with netcat.

share|improve this answer
add comment

What you are trying to achieve is not possible without root permission.

share|improve this answer
    
I don't need to listen UDP packets that arrive to any port. The target ip port is specified, but not the source. This is possible as a normal user, and as a side note I've alredy written a minimal c program that can do it, but I asked because I lost half an hour trying to get nc to do it, and now I want to know if it's totally impossible with common shell utilities. –  Lorenzo Pistone Jul 15 '12 at 19:16
    
aaah so you are trying to connect to a port? –  Lucas Kauffman Jul 15 '12 at 20:18
    
no, the source port will change at every packet. –  Lorenzo Pistone Jul 16 '12 at 10:17
add comment
up vote 0 down vote accepted

With some nc versions, it's possible to specify a -k option:

-k Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option. When used together with the -u option, the server socket is not connected and it can receive UDP datagrams from multiple hosts.

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.