English 中文(简体)
Can I use Bonjour from command line?
原标题:

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?

问题回答

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".

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

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





相关问题
C# Networking API s [closed]

Lately I ve been looking for a good networking API i could possibly use and/or reference some of the code within, but i have mere luck searching for some on Google/Bing. Hopefully somebody here has ...

Listen to a port that is in use [duplicate]

Possible Duplicate: Get connecting IP from specified ports that using by other program. If a port is used by a program, is there any way I can listen that port and get the connected IP on that ...

Twisted Spread suitable for multiplayer racing sim?

Do you think that Twisted Spread may be suitable (in terms of performance) for a multiplayer racing simulator? The rest of the application is based on Python-Ogre. Can Perspective Broker run upon (...

Optimizing a LAN server for a game

I m the network programmer on a school game project. We want to have up to 16 players at once on a LAN. I am using the Server-Client model and am creating a new thread per client that joins. ...

multicast ip address - blocked in call to recvfrom

i am writing a simple multicast application. i intend to run it on localhost. i have done the following: char *maddr; . . . sendfd = socket(...); struct sockaddr_in sasend; sasend.sin_family = ...

Java HTTPAUTH

我试图把桌面应用程序连接起来,我是同D.icio.us api @ Delicious Alan书写的,简单地向他们提供我的用户名和密码,并请他把书记上写给我......。

热门标签