17

Is it possible to use Bonjour from command line? For example if I want to register a service I type something like that: bonjour -register service_name port. And then Bonjour allocate a free IP for my service. Or, for example, if I want to see a list of available services I type something like: bonjour -showServices. And then I get list of all available services with their names, IP addresses and ports. Does something like that exist?

I am kind of confused by the available documentation. For example here, in the beginning of the document I see:

To register your service, call DNSServiceRegister.

Where should I call it? In the command line? In Java? In C++? In python? It is kind of strange that this kind of context is not provided.

In general, I find just a general information about zeroconf and Bonjour (what it is supposed to do). But I cannot find something concrete and simple. Like "Hello World" examples of usage of Bonjour.

Can anybody help me with that?

Roman
  • 124,451
  • 167
  • 349
  • 456
  • Thanks a lot for the answer. They help but Is still did not get the answer on my question: "Can I use Bonjour from command line?". Max, mDNS is not not for Windows (which I need). jdizzle, dns-sd is very close to what I need but it is not Bonjour, right? May be dns-sd is used by Bonjour? – Roman Mar 05 '10 at 09:19
  • I found an example of a real-world use of Bonjour from the command line, to advertise a printer on another machine that doesn't support mDNS. You might find it answers some of your questions: http://playcontrol.net/ewing/jibberjabber/advertising_a_legacy_networ.html – Max Mar 05 '10 at 09:27
  • dns-sd is a command line tool to register/browse bonjour announcements. It is exactly what you say you want, but I bet what you really want is a bonjour API for your application to use, which also exist. – jdizzle Feb 26 '12 at 04:42

3 Answers3

29

dns-sd is the command line program that works on both windows and Mac OS X.

I often use it to tunnel iTunes shares over the internet with ssh. My typical use is dns-sd -P my_music _daap._tcp. local 3690 localhost 127.0.0.1. This assumes that I've set up an ssh tunnel listen on localhost port 3690 to port 3689 of the host sharing iTunes on the foreign network. This makes a little iTunes share icon appear in iTunes named "my_music".

jdizzle
  • 4,078
  • 1
  • 30
  • 38
6

mDNS is an older version of the dns-sd tool. They are both command line tools, written by Apple, to interact with Bonjour.

You can use the command line tool to do a few things with Bonjour, but to quote from the dns-sd man page:

The dns-sd command is primarily intended for interactive use. Because its command-line arguments and output format are subject to change, invoking it from a shell script will generally be fragile.

If you wish to perform DNS Service Discovery operations from a scripting language, then the best way to do this is not to execute the dns-sd command and then attempt to decipher the textual output, but instead to directly call the DNS-SD APIs using a binding for your chosen language.

For example, if you are programming in Ruby, then you can directly call DNS-SD APIs using the dnssd package documented at http://rubyforge.org/projects/dnssd/. Similar bindings for other languages are also in development.

For example, you asked about "DNSServiceRegister", which is a C function:
http://developer.apple.com/library/mac/#documentation/Networking/Reference/DNSServiceDiscovery_CRef/dns_sd_h/index.html#//apple_ref/c/func/DNSServiceRegister

Peter Bierman
  • 236
  • 2
  • 3
1

Yes, it is certainly possible. Take a look at the man page for mDNS

Max
  • 2,121
  • 3
  • 16
  • 20
  • But I think mDNS is for Mac OS, isn't? I need to use Windows XP. – Roman Mar 04 '10 at 13:20
  • 2
    Buy the way, is mDNS a part of Bonjour? Or, how mDNS and Bonjour are related? – Roman Mar 04 '10 at 13:21
  • Yes, mDNS is a Mac OS/UNIX program. mDNS is a part of Bonjour (what used to be called Rendezvous) which is Apple's implementation of Zeroconf networking. Take a look at the reference material on Apple's website: http://developer.apple.com/networking/bonjour/index.html. – Max Mar 04 '10 at 13:45
  • Is there something similar for Windows? – Roman Mar 04 '10 at 13:52
  • I'm not sure if the command-line tools are part of Apple's Bonjour for Windows. Why not download it & check? If you sign up for a (free) ADC account, I believe you can download source code as well. – Max Mar 04 '10 at 14:20
  • I have just installed Bonjour on my Windows. After that I tired "mDNS" in the command line and the command was not found. But in the "Program Files\Bonjour" I found "mDNSResponder.exe". I do not know if it is the same. – Roman Mar 04 '10 at 14:33
  • No it's not the same - that is the daemon that listens for mDNS queries and responds to them. There is a good video talk by Stuart Cheshire, the inventor of zeroconf networking, explaining how it all works here: http://video.google.com/videoplay?docid=-7398680103951126462# (I discovered Stuart Cheshire went to the same school as I did!) – Max Mar 04 '10 at 14:56
  • @Max - Link dead, looks like this one may be same thing? https://www.youtube.com/watch?v=ZhtZJ6EsCXo – gregmac Jun 16 '15 at 02:53