faz com que o netcat ouça vários pacotes UDP

5

Se eu executar um ouvinte de UDP simples como este:

nc -l -u -p 1234

Depois, aparece apenas o primeiro pacote UDP de entrada. Por exemplo, se eu correr:

$ echo abc | nc -u localhost 1234
  ["abc" appears in output of server as expected]

$ echo abc | nc -u localhost 1234
read(net): Connection refused
    
por Alex Flint 26.04.2016 / 22:51

2 respostas

5

usando um tempo limite de zero (0)

"Servidor":

nc -kluvw 0 localhost 9000

"Cliente":

echo -e "all"     | nc -vuw 0 localhost 9000
echo -e "the"     | nc -vuw 0 localhost 9000
echo -e "udp"     | nc -vuw 0 localhost 9000
echo -e "packets" | nc -vuw 0 localhost 9000

Resultado:

Connection from 127.0.0.1 port 9000 [udp/*] accepted
all
Connection from 127.0.0.1 port 9000 [udp/*] accepted
the
Connection from 127.0.0.1 port 9000 [udp/*] accepted
udp
Connection from 127.0.0.1 port 9000 [udp/*] accepted
packets

testado com:

uname -a
Linux ubuntu 3.2.0-23-generic-pae #36-Ubuntu SMP Tue Apr 10 22:19:09 UTC 2012 i686 i686 i386 GNU/Linux
    
por 06.02.2017 / 22:58
0

Encontrei um link que pode ajudá-lo: netcat: comportamento estranho com UDP - só recebe primeiro pacote enviado .

At this stage I wasn’t sure what to do but Nathan pointed out that if I made use of timeouts on the client and server then it would be possible to send multiple UDP packets.

I restarted the netcat server but this time with a 1 second timeout:

$ nc -kluvw 1 localhost 9000

And then started sending UDP packets from a netcat client also with a 1 second timeout:

 $ echo -e "all" | nc -vvuw 1 localhost 9000
 Connection to localhost 9000 port [udp/cslistener] succeeded!
 $ echo -e "the" | nc -vvuw 1 localhost 9000
 Connection to localhost 9000 port [udp/cslistener] succeeded!
 $ echo -e "udp" | nc -vvuw 1 localhost 9000
 Connection to localhost 9000 port [udp/cslistener] succeeded!
 $ echo -e "packets" | nc -vvuw 1 localhost 9000
 Connection to localhost 9000 port [udp/cslistener] succeeded!

And the netcat server now receives all of them:

$ nc -kluvw 1 localhost 9000
XXXXall
XXXXthe
XXXXudp
XXXXpackets

Este foi um problema interessante, espero que isso responda à sua pergunta.

    
por 27.04.2016 / 00:15

Tags