Last active
June 1, 2022 17:55
-
-
Save ThomasRooney/66d6fa300105cd0970e1a25eeb4e80b1 to your computer and use it in GitHub Desktop.
Discover Chromecast with devicename via mDNS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /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