Skip to content

Instantly share code, notes, and snippets.

@ThomasRooney
Last active June 1, 2022 17:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ThomasRooney/66d6fa300105cd0970e1a25eeb4e80b1 to your computer and use it in GitHub Desktop.
Save ThomasRooney/66d6fa300105cd0970e1a25eeb4e80b1 to your computer and use it in GitHub Desktop.
Discover Chromecast with devicename via mDNS
#! /bin/sh
if ! which dns-sd > /dev/null
then
echo "Requires dns-sd"
exit
fi
if (( $# < 1 )) ; then
echo "Requires devicename as an argument"
exit
fi
deviceName=$*
timeout=5
fifo=/tmp/discover.fifo
rm -f $fifo
mkfifo $fifo
dns-sd -G v4 "$deviceName".local >$fifo &
pid1=$!
while read line; do
case $line in *.local*)
echo $line | cut -d ' ' -f 6
break
esac
done <$fifo &
pid2=$!
sleep $timeout && kill $pid1 $pid2 &
pid3=$!
wait $pid2
kill $pid3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment