Skip to content

Instantly share code, notes, and snippets.

@mneedham
Last active December 20, 2015 08:59
Show Gist options
  • Select an option

  • Save mneedham/6104020 to your computer and use it in GitHub Desktop.

Select an option

Save mneedham/6104020 to your computer and use it in GitHub Desktop.
netcat UDP
# Start up netcat server
nc -kluv localhost 9000
# Check it with lsof
$ lsof -Pni :9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nc 59231 markneedham 5u IPv6 0xd2ab0eedfdf2c00b 0t0 UDP [::1]:9000
# Send a UDP packet and see it's received
$ echo -n "mark" | nc -vvu localhost 9000
Connection to localhost 9000 port [udp/cslistener] succeeded!
# Try to send another packet which doesn't get received
# Check lsof and see there is now a socket between 9000 and an ephemeral port (presumably from the first packet sent)
$ lsof -Pni :9000
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nc 59231 markneedham 5u IPv6 0xd2ab0eedfdf2c00b 0t0 UDP [::1]:9000->[::1]:60845
@nfisher
Copy link
Copy Markdown

nfisher commented Jul 29, 2013

# Start nc server, wait 1s for read
nc -kluvw 1 localhost 9000

# send packet
echo -n "mark" | nc -vvuw1 localhost 9000

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment