Last active
December 11, 2015 04:49
-
-
Save gongo/4547941 to your computer and use it in GitHub Desktop.
AppleTV の IP アドレスを検出する。LAN 内に複数 AppleTV ある時の動作はわかりません。OSX 10.8 & Emacs 24.2 、及び Ubuntu 12.04 & Emacs 23.2 で動作確認 http://gongo.hatenablog.com/entry/2013/01/17/004306
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
(require 'dns) | |
(with-temp-buffer | |
(let ((process (make-network-process :name "mdns" | |
:coding 'binary | |
:buffer (current-buffer) | |
:host "224.0.0.251" | |
:service 5353 | |
:type 'datagram)) | |
(send-text (dns-write | |
`((id ,(random 65000)) | |
(opcode query) | |
(queries (("_airplay._tcp.local" (type PTR))))))) | |
response ip) | |
(process-send-string process send-text) | |
(when (zerop (buffer-size)) | |
(accept-process-output process 5)) ;; wait 5sec | |
(setq response (buffer-string)) | |
(delete-process process) | |
(if (zerop (length response)) nil | |
(dns-get 'data (car (dns-get 'additionals (dns-read response))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment