0

I'm trying to write a script that listens for broadcasted UDP packets on port 2088, read the data, and then POST to an URL. Specifically, I'm trying to make a LIFX light turn red when I'm on the phone. Whenever our phones change state (off-hook, on-hook, ringing, etc) it broadcasts its state on UDP 2088.

So, the pseudo-code would be something like:

Start Loop
Listen for UDP 2088 from source [my phone]
If data = [x] then send command to turn on lamp
else if data = [y] send command to turn off lamp

The biggest problem is I'm not sure how to actually grab the data from the packet. It is readable in Wireshark, but when I run, for example, netcat, I get output that is unreadable.

$ netcat -u -l 2088 -vv
Bound on 0.0.0.0 2088
Connection received on 192.168.250.51 2088
 ^C5

Thanks!

1 Answer 1

1

The only way I know to get netcat to exit after a UDP packet is with a busy loop and a timeout

while :
do
    data=$(nc -u -l -p 2088 -w 1 </dev/null 2>/dev/null)
    [ -n "$data" ] && printf "%s\n" "$(printf "%s" "$data" | hex)"
done

Tickle it with this type of code

echo hello | nc -q 1 -w 1 -u "$listeningHost" 2088

There are at least two different versions of netcat available. This example definitely works with traditional; I haven't tested with openbsd. Don't test on a single host - you really do need two connected hosts for this

1
  • Thanks. Ended up getting waylaid by other projects. I'll test soon hopefully.
    – pooter03
    Mar 16, 2021 at 14:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .