我可以从命令行使用 Bonjour 吗?

发布于 2024-08-23 09:10:09 字数 653 浏览 5 评论 0原文

是否可以从命令行使用 Bonjour?例如,如果我想注册一个服务,我可以输入类似的内容:bonjour -register service_name port。然后Bonjour为我的服务分配一个免费的IP。或者,例如,如果我想查看可用服务的列表,我可以输入以下内容:bonjour -showServices。然后我得到所有可用服务的列表及其名称、IP 地址和端口。存在这样的东西吗?

我对可用的文档有点困惑。例如 这里,在文档的开头我看到:

要注册您的服务,请致电 DNS服务注册。

我应该在哪里调用它?在命令行中?在爪哇?在C++中?在蟒蛇?没有提供这种上下文有点奇怪。

一般来说,我只找到有关 Zeroconf 和 Bonjour 的一般信息(它应该做什么)。但我找不到具体而简单的东西。就像“Hello World”使用 Bonjour 的例子一样。

有人可以帮我吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

装迷糊 2024-08-30 09:10:09

dns-sd 是可在 Windows 和 Mac OS X 上运行的命令行程序。

我经常使用它通过 ssh 通过互联网隧道传输 iTunes 共享。我的典型用法是 dns-sd -P my_music _daap._tcp。本地 3690 本地主机 127.0.0.1。假设我已经在本地主机端口 3690 上设置了一个 ssh 隧道,监听到在外部网络上共享 iTunes 的主机的端口 3689。这使得 iTunes 中出现一个名为“my_music”的 iTunes 共享小图标。

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

生活了然无味 2024-08-30 09:10:09

mDNS 是 dns-sd 工具的旧版本。它们都是由 Apple 编写的命令行工具,用于与 Bonjour 交互。

您可以使用命令行工具对 Bonjour 执行一些操作,但引用 dns-sd 手册页:

dns-sd 命令主要用于交互式使用。由于它的命令行参数和输出格式可能会发生变化,因此从 shell 脚本调用它通常很脆弱。

如果您希望从脚本语言执行 DNS 服务发现操作,那么最好的方法不是执行 dns-sd 命令,然后尝试解密文本输出,而是直接调用 DNS- SD API 使用您选择的语言的绑定。

例如,如果您使用 Ruby 进行编程,则可以使用 http://rubyforge.org/projects/dnssd/
其他语言的类似绑定也在开发中。

例如,您询问“DNSServiceRegister”,这是一个 C 函数:
http://developer.apple.com/library/mac/#documentation/Networking/Reference/DNSServiceDiscovery_CRef/dns_sd_h/index.html#//apple_ref/c/func/DNSServiceRegister

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

岁月苍老的讽刺 2024-08-30 09:10:09

是的,这当然是可能的。查看 的手册页mDNS

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文