How do I get the machine name from an IP via Multicast DNS?

Since you already know the IP addresses you can look up the reverse entry for each IP address to get the associated forward address:

$ dig -x 10.0.0.200 @224.0.0.251 -p 5353

; <<>> DiG 9.6.0-APPLE-P2 <<>> -x 10.0.0.200 @224.0.0.251 -p 5353
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 54300
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; QUESTION SECTION:
;200.0.0.10.in-addr.arpa.   IN  PTR

;; ANSWER SECTION:
200.0.0.10.in-addr.arpa. 10 IN  PTR atj-mbp.local.

;; ADDITIONAL SECTION:
atj-mbp._device-info._tcp.local. 10 IN  TXT "model=MacBookPro3,1"

;; Query time: 2 msec
;; SERVER: 10.0.0.200#5353(224.0.0.251)
;; WHEN: Sat Jun 26 07:53:44 2010
;; MSG SIZE  rcvd: 126

For a more shell script friendly output, use '+short':

$ dig +short -x 10.0.0.200 @224.0.0.251 -p 5353
atj-mbp.local.

Depending on your intended use case there may be a more appropriate method of performing the query. Feel free to contact me if you should need any further information.


On Linux, you can use the getent command from the libc:

getent hosts 192.168.0.52

Or install avahi-utils, and run

avahi-resolve-address 192.168.0.52

This appears to work:

dig -x 192.0.2.42 -p 5353 @224.0.0.251

From Fun with multicast DNS