Netcat

讓 netcat 監聽多個 UDP 數據包

  • December 19, 2021

如果我像這樣執行一個簡單的 UDP 偵聽器:

nc -l -u -p 1234

然後我似乎只得到了第一個入站 UDP 數據包。例如,如果我執行:

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

$ echo abc | nc -u localhost 1234
read(net): Connection refused

使用零 (0) 超時

“伺服器”:

nc -kluvw 0 localhost 9000

“客戶”:

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

結果:

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

測試:

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

引用自:https://serverfault.com/questions/773110