FROM: NETWORKSHOP
SKILL LEVEL: AGILE
Introduction
In public space we can speak to ourselves, another person or to everybody. This latter kind of speaking is known as shouting.
On a computer network the equivalent comes in the form of ‘broadcast’ packets, sent to every single host (computer, smartphone, router) on the same network subnet you are on. Such packets are used to manage aspects of the network’s functionality or announce services such as network printer sharing.
Here is a command that will shout at every device on the network you’re on, should you ever feel the need. Perhaps someone is capturing packets and hears you. It uses the program socat available for GNU/Linux systems:
Example code
These compound commands will send a UDP-DATAGRAM packet out to all hosts on the network you’re on. See the code comments for details:
# Define a variable NET that finds extracts the current network through
# which we have a gateway from our routing table, filtering with grep (UG)
# and awk and using cut to chop the last part of the address down to
# 3 fields (eg 192.168.0). head is used to select the first line in output.
NET=$(route -n|grep UG|awk '{print $2}'|cut -d '.' -f1-3 | head -n 1)
# echo a string "ROAR!" to socat's standard input via a UNIX pipe.
# append ".255" (broadcast address to $NET) on port 5000.
echo "R O O O O A A R R R R !"|socat - UDP-DATAGRAM:$NET.255:5000,broadcast
This can be made into a shell script, taking whatever you want to shout as an input argument, like so:
#!/bin/bash
# Define a variable YELL from the first input argument ($1)
YELL=$1
NET=$(route -n|grep UG|awk '{print $2}'|cut -d '.' -f1-3 | head -n 1)
# Pass YELL to socat via a UNIX pipe.
echo $YELL | socat - UDP-DATAGRAM:$NET.255:5000,broadcast
Save this out as a shell script ‘shout.sh’, make it executable with chmod (+x adds the executable property) and execute as follows, using whatever input argument you like:
chmod +x shout.sh
sudo ./shout.sh "I SEE YOU WOLF."