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