Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I would be interested in knowing which programs advertise themselves using Bonjour on my machine. Is there a way to do that?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

The dns-sd command-line tool can be helpful for this, but learning to use it is a bit tricky.

Running dns-sd -B _services._dns-sd._udp will return a list of all available service types that currently being advertised. (The list is per interface, so there will be some redundancy.) If this is done on a Mac with no active network connection, the list will of course only contain services running on that machine.

Using that list, you can request information about the individual services types by running things like dns-sd -B _home-sharing._tcp (which lists iTunes Home Sharing instances), and then, given an instance name, you can run dns-sd -L "Wes Campaigne’s Library" _home-sharing._tcp to lookup information for a particular instance.

To be honest, though, this whole process is rather tedious, and it's exactly what Bonjour Browser was built to do, so I highly recommend using that. (The app might be ancient, but it still works.) Whichever way you do it, though, it may not always be clear what program is responsible for a given service entry.

You can use the strategy given in binarybob's answer to try to map service entries to running processes based on port number, but this may not always work. Another strategy is to run something like dns-sd -B _home-sharing._tcp which remains open and reports when instances are added or removed, then, one by one, quit various apps and (assuming it's not a system service) see which one's quitting triggers the removal message.

share|improve this answer
    
Looks like the music sharing service is now called _daap though. –  zneak Jan 3 '13 at 5:42
    
Actually, DAAP refers the older of iTunes' two separate forms of library sharing. DAAP is enabled through Preferences > Sharing > Share my library on my local network. Home Sharing, added in iTunes 9, is enabled through File > Home Sharing. It uses your Apple ID for authentication. –  Wes Campaigne Jan 6 '13 at 20:54
add comment

Although classified as a legacy article, this very may well be what you are looking for: DNSServiceMetaQuery. As outlined by the documentation:

This sample uses DNSServiceQueryRecord to send a Multicast DNS query that returns a list of Bonjour service types being advertised on the local network. Machines must be running mDNSResponder-58.6 (Mac OS X 10.3.4) or later in order to respond to this query.

To run DNSServiceMetaQuery on Mountain Lion (the included build does not run properly), go to the sample code link and click Download Sample Code. Then, install Xcode if you haven't already. Create a new project under the template of Mac OS X > Application > Command Line Tool.

Open and copy all text in ~/Downloads/DNSServiceMetaQuery/DNSServiceMetaQuery.cand paste it into main.c of your new Command Line Tool project (replacing everything that was there in the template). Next, you'll need to add CoreFoundation.framework to the project by clicking the project name in the sidebar > Build Phases and open the dropdown arrow next to Link Binary With Libraries. Click the + button, search for CoreFoundation.framework, and add it. Then click the Run button (looks like a play button) and wait for a Build Succeeded image. Something should come from the button of the window with a log; this will display all of your Bonjour services. Make sure All Output is checked.

share|improve this answer
    
I'm a proficient programmer, so I know my way around Xcode (and that's a good thing because I'm not sure I would like to install Xcode just for that). I'll check it out, thanks! –  zneak Sep 29 '12 at 18:40
add comment

Although it might not satisfy your exact criteria, Tildesoft's Bonjour Browser can list all the all the bonjour services advertised on your local network and the hosts that are advertising them.

I guess for locally advertised services you could drill down in Bonjour Browser to find the port number the service is advertised on, then use lsof to determine the application associated with it, For example:

lsof -i | grep 57857

gives

iTunes    36720   ...     TCP *:57857 (LISTEN)

when I have iTunes running.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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