12

Apple's Finder.app is able to consistently determine the exact model of each physical computer that uses bonjour (as evidenced by the icons being unique for each individual device type: iMac, MacPro, MBP, etc). How do they do this and what APIs do they use?

On a side note, Bonjour provides Name, Service Type, Domain and Port for all services on the network - but I haven't been able to find information on how to find the device model itself.

2 Answers 2

12

I believe this uses the _device-info._tcp. mDNS record for the IP address. You can see this for yourself. In the terminal, you can use dig @224.0.0.251 -p5353 to perform mDNS requests. You can use dig @224.0.0.251 -p5353 Foo.local. to resolve the IP address of the computer Foo.local. Take that IP and plug it back into dig @224.0.0.251 -p5353 -x $IP and you should see something like the following:

> dig @224.0.0.251 -p5353 -x 10.0.1.1
; <<>> DiG 9.6.0-APPLE-P2 <<>> @224.0.0.251 -p5353 -x 10.0.1.1
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22887
;; flags: qr aa; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

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

;; ANSWER SECTION:
1.0.0.10.in-addr.arpa.  10  IN  PTR Foo.local.

;; ADDITIONAL SECTION:
Foo._device-info._tcp.local. 10 IN TXT  "model=MacBookPro5,3"

;; Query time: 4 msec
;; SERVER: 10.0.0.1#5353(224.0.0.251)
;; WHEN: Mon Nov 29 18:00:23 2010
;; MSG SIZE  rcvd: 131

Notice the ADDITIONAL SECTION.

Unfortunately, I don't know how to get at this information using the Bonjour APIs.

Edit: You can also get this info in a single query with dig @224.0.0.251 -p5353 Foo._device-info._tcp.local. TXT.

8
  • thanks that's very cool! In case someone else has the same problem, you can pick out the model using: dig @224.0.0.251 -p5353 BigMac._device-info._tcp.local. TXT |grep model|awk ' { print $5 }'| sed -e 's/"model=//;s/"//' If someone knows how to do this using Apple's APIs I'm still interested in that. Nov 30, 2010 at 2:27
  • this works fine for all the Apple gear on my network, but for a "Brother DCP-8085DN" printer announcing itself under _printer._tcp. I get "connection timed out; no servers could be reached" - could you please provide some information on when should I expect dig to work? Thanks!!! Nov 30, 2010 at 2:44
  • You should expect it to work for Apple gear. Most likely no other device supports it, but that's really up to the device. I imagine printer information (used for displaying the printer icon) is given as part of the TXT record for the appropriate bonjour service, rather than as extra data like this model apparently is. Nov 30, 2010 at 2:52
  • macOS Sierra doesn't seem to give out any _device-info bonjour entries, even with services turned on.
    – adib
    Jan 31, 2017 at 10:12
  • @adib I just tested on my laptop running OS X 10.12.3 (16D32) and I still see it: Kefka._device-info._tcp.local. 10 IN TXT "model=MacBookPro11,4" "osxvers=16" Feb 1, 2017 at 19:18
8

OSX is broadcasting this information if certain network services are running on this machine. To my knowledge these are _afpovertcp, _rfb and _airport (Airport router only of course). You are looking for a bonjour service called _device-info._tcp. The trouble is, that it is not showing up via a simple

[someNSNetServiceBrowserInstance searchForServicesOfType:@"_services._dns-sd._udp." inDomain:@""];

Instead you need to start monitoring a specific Host which you think could broadcast _device-info._tcp.

NSNetService *aNetService = [[NSNetService alloc]initWithDomain:@"" type:@"_device-info._tcp." name:@"MyFancyIMacWithAFPOn"];
    [aNetService setDelegate:self];
    [aNetService startMonitoring];

Implement the callback

- (void)netService:(NSNetService *)sender didUpdateTXTRecordData:(NSData *)data

Which will give you the deviceModel string.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.