如何添加“查看本地网络上的其他计算机”功能?
假设我有一个名为 super-dupper-app 的桌面软件。我希望它能够检测到该本地网络上运行 super-dupper-app 的所有计算机。
非常感谢一般指点。 Python 指针或片段的奖励积分。
Let's say I have a desktop software called super-dupper-app. I want it to be able to detect all computers on this local network with super-dupper-app running.
General pointers really appreciated. Bonus points for Python pointers or snippets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的答案是您使用python 中的多播数据包。我相信 avahi 也有 python 绑定,它实现了“ZeroConf”,又名 mDNS/DNS-SD,它是在多播的顶部,可以让您不必重新发明轮子并变得更加标准。
多播位于单播(数据包发送到一台主机)和广播(数据包发送到所有主机)之间,因为它允许主机(通常通过在其上运行的应用程序)注册对某些多播组的兴趣。在适当的支持下,多播流量可以跨路由器和交换机,其想法是构建最小生成树,用于将数据包发送到所有订阅的主机。在 IPv4 中,多播使用 224/4 子网。对于 IPv6,这是 ff00::/8。在以太网中,多播地址被映射到MAC地址(即,将MAC地址中的多播位设置为1),这使得有效过滤多播流成为可能。
例如,运行 RIPv2 的路由器使用多播来发现其他相邻路由器并共享其路由,而不会打扰对 RIP 不感兴趣的主机。
mDNS/Bonjour/Rendevouz 是一种自动服务发现,使用一个多播组来共享列出 LAN 上可用服务的 DNS 样式消息。
The short answer is you use multicast packets in python. I believe there are also python bindings for avahi, which implements "ZeroConf" aka mDNS/DNS-SD, which is implemented on top of multicast and would save you having to reinvent the wheel as well as being more standard.
Multicast sits somewhere in between unicast (packets going to one host) and broadcast (packets going to all hosts) in that it allows host (via applications running on them usually) to register an interest in certain multicast groups. Multicast traffic can cross routers as well as switches, with appropriate support and the idea is that a minimum spanning tree gets built for sending packets to all subscribed hosts. In IPv4 multicast uses the 224/4 subnet. For IPv6 this is ff00::/8. In ethernet multicast addresses are mapped onto MAC addresses (i.e. have the multicast bit set to 1 in the MAC address), which makes efficient filtering of multicast streams possible.
Routers running RIPv2 for example use multicast to discover other neighbouring routers and share their routes without bothering hosts which have no interest in RIP.
mDNS/Bonjour/Rendevouz is an approach to automatic service discovery that uses one multicast group to share DNS style messages listing available services on a LAN.