How do I obtain “model name” for a networked device (potentially using Bonjour)?

牧云@^-^@ 提交于 2019-12-03 07:26:21

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4309740/how-do-i-obtain-model-name-for-a-networked-device-potentially-using-bonjour

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!