Skip to content

Instantly share code, notes, and snippets.

@mrevjd
Forked from ThomasRooney/discover-chromecast.sh
Created August 26, 2020 01:29
Show Gist options
  • Select an option

  • Save mrevjd/05f28f796d9e58285200db6a414f7df6 to your computer and use it in GitHub Desktop.

Select an option

Save mrevjd/05f28f796d9e58285200db6a414f7df6 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