18

I have a list of IP addresses on a network, and most of them support multicast DNS. I'd like to be able to resolve the server name instead of just having the IP address.

ping computer.local
64 bytes from 192.168.0.52: icmp_seq=1 ttl=64 time=5.510 ms
64 bytes from 192.168.0.52: icmp_seq=2 ttl=64 time=5.396 ms
64 bytes from 192.168.0.52: icmp_seq=3 ttl=64 time=5.273 ms

Works, but I'd like to be able to determine that name from the IP. Also the devices don't necessarily broadcast any services, but definitely do support mDNS broadcast. So looking through services won't work.

Adam
  • 301
  • 1
  • 3
  • 6
  • 1
    What OS are you using? [mdns-scan](http://packages.ubuntu.com/lucid/mdns-scan) seems to be an option on linux. – Zoredache May 19 '10 at 00:24
  • 2
    OS X, but if I can get a linux solution, I'm sure I can find an analogue in the mac world. mdns-scan looks for broadcasted services, so that's not going to work. Some of the devices don't broadcast any services, but will resolve their address when queried by name. – Adam May 19 '10 at 02:05

4 Answers4

28

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.

andrewtj
  • 636
  • 4
  • 5
  • 2
    Any idea why this might fail against an iOS device that is not running any Bonjour services? It works against a Mac that is not otherwise running any Bonjour services. – John Wright Sep 19 '13 at 02:35
  • Worth noting that you can also find out which IP addresses are on the network using `arp-scan` installed from homebrew or macports. Or, if you just want to get a feel for the hosts on the network, you could look at your current ARP table using a command already on OS X: `arp`. Specifically, you can use the command `arp -n -i -l -a`, where `` should be the name of the network interface you're curious about (e.g. `en0`). – Parthian Shot Mar 11 '16 at 18:52
9

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
Tobu
  • 4,367
  • 1
  • 23
  • 31
  • The package is `avahi-tools` on Fedora and it's the only thing on this page that worked :) – Navin Jun 14 '17 at 12:47
4

This appears to work:

dig -x 192.0.2.42 -p 5353 @224.0.0.251

From Fun with multicast DNS

Rick
  • 141
  • 4
-1

Well I did a fair bit more research on this one, and looking through mDNDS and the protocol, it looks like this isn't actually possible. There is a lookup request on the protocol for name retrieval, so when you ask for a name the appropriate client will respond, but there is not lookup request for an IP. There's no central store for addresses either.

Hope this help someone else, as I've spent way too much time tracking this down.

If anyone has any other ideas on this issues, I've love to hear em.

Adam
  • 301
  • 1
  • 3
  • 6