广播主机名和 IP 地址

发布于 2024-07-16 20:52:56 字数 166 浏览 2 评论 0原文

为了通知同一 LAN 内的所有计算机我的存在,我想广播我的主机名和IP地址。

我该如何做到这一点而不将它们作为字符串发送?

In order to notify all computers within the same LAN about my existence, I want to broadcast my hostname and IP address.

How do I go about doing so without sending them as a string?

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

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

发布评论

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

评论(3

百变从容 2024-07-23 20:52:57

基本上重新发明 NetBIOSZeroConf,在小型嵌入式设备中很流行,可通过基于 Windows 或 OS X 的安装程序或设置实用程序进行发现。

Basically re-inventing NetBIOS or ZeroConf, as popular with small embedded devices for discovery by a Windows or OS X based installer or setup utility.

沙与沫 2024-07-23 20:52:57

您可以尝试使用UPnP Discovery

You can try to use UPnP Discovery.

み青杉依旧 2024-07-23 20:52:56

Avik,这就是 DNS 的用途。 虽然“常规”DNS 旨在保存每台计算机(静态配置)的名称和 IP 地址,但动态 DNS 协议允许计算机实时更新其 DNS 条目。

我的客户在某些办公环境中使用了这种功能,其中机器上的打印机是共享的,但它们连接的机器使用 DHCP(意味着它们的 IP 地址可以更改)。

请参阅此处此处了解详细信息以及使用 DHCP 的 Windows 实现。

让我们将想要宣传自己的机器称为“服务器”,将所有可以使用它的机器称为“客户端”。

当然,动态 DNS 仅通知 DNS 本身名称/IP 映射,并且如果客户端已经知道您的服务器以便他们可以从 DNS 获取 IP 地址,则动态 DNS 非常有用。 如果您无法让客户端发现您的服务器刚刚被添加,您仍然需要偶尔广播一个数据包来表明您的服务器存在(这只需要服务器名称,因为客户端将使用 DNS 来获取 IP 地址) )。

该广播数据包应被所有客户端接收并保存在本地表中。 如果从客户端到您的服务器的通信失败,则应删除您的服务器的本地表条目(当您的服务器再次广播时,它将重新添加)。

Avik, this is what DNS is meant to be used for. While "regular" DNS is meant to hold names and IP addresses for each machine (statically configured), there is a dynamic DNS protocol which allows machines to update their DNS entries in real time.

This sort of capability is used in some of the office environments for my clients where printers on a machine are shared but the machines they're attached to use DHCP (meaning their IP address can change).

See here and here for details and the Windows implementation with DHCP.

Lets call your machine that wants to advertise itself the SERVER and all the machines that can use it, the CLIENTS.

Of course, dynamic DNS only notifies DNS itself of the name/IP mapping and is useful if the CLIENTS are already aware of your SERVER so they can get the IP address from DNS. If you have no way for CLIENTS to discover that your SERVER has just been added, you'll still need to broadcast a packet occasionally indicating that your SERVER exists (this will only need the SERVER name since CLIENTS will use DNS to get the IP address).

This broadcast packet should be picked up by all CLIENTS and kept in a local table. If the communications from a CLIENT to your SERVER fails, the local table entry for your SERVER should be removed (it'll be re-added when your SERVER broadcasts again).

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