自动检测连接到网络的新计算机

发布于 2024-09-02 09:31:35 字数 188 浏览 3 评论 0原文

有没有一种优雅的方法可以让程序检测连接到网络的新计算机?

我希望我的程序能够“自动感知”网络上连接的新计算机(它们位于同一网络上)。就像 USB 设备连接到计算机一样。

我现在所做的就是不时保存网络中所有计算机的列表。另一种方法是 PING 子网上的所有可用 IP。

还有其他优雅的方法吗?

谢谢!

Is there an elegant way to make a program detect a new computer that is connected to the network?

I would like my program to "auto-sense" a new computer being connected on the network (they're on the same network). Like a USB device being connected to the computer.

What I'm doing now is to save a list of all computers in the network from time to time. Another approach is to PING all available IPs on the subnet.

Are there any other elegant approaches?

Thanks!

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

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

发布评论

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

评论(2

剩一世无双 2024-09-09 09:31:35

侦听 ARP 请求是执行此操作的规范方法。无论是否独立于 DHCP,任何希望与外界通信的连接计算机都必须向默认路由器的地址发出 ARP 请求。该请求将以广播形式发出,并包含源接口的 MAC 和 IP 地址。

如果另一台计算机使用 DHCP,它会向自己的地址发出 ARP 请求,作为重复地址检测的一部分,这也是您可以窥探的广播。

(这与 IPv6 的工作方式大致相同,只是您需要寻找邻居发现或路由器请求数据包。)

就像提到的答案一样,如果您有一台可以 telnet 或使用 SNMP 的交换机,您可以提取 MAC 表。这将为您提供交换机中每个端口上的 MAC 地址列表。然而,如果您想要 IP 地址,您仍然需要侦听 ARP:s。

另一方面,如果您可以访问网络上的默认网关,您还可以查看那里的 ARP 表。这将为您提供最近与之通信的任何人的 MAC 和 IP 地址(对于最近的不同值...)。

Listening for ARP requests is the canonical way to do this. Independent of DHCP or not, any connected computer that wishes to communicate with the outside world will have to make an ARP request for the address of the default router. This request will go out as a broadcast, and contain the source interface's MAC and IP adresses.

If the other computer uses DHCP, it will make an ARP request for it's own address as part of duplicate address detection, which is also a broadcast you can snoop on.

(This works more or less the same way for IPv6, except you need to look for neighbor discovery or router soliciation packets instead.)

Like the answer alluded to, if you have a switch to which you can telnet or use SNMP on, you can extract the MAC table. That will give you a list of MAC adresses on each port in the switch. If you want the IP addresses however, you still need to listen for ARP:s.

On the other hand, if you have access to the default gateway on the network, you can also look at the ARP table there. That will give you MAC and IP addresses for anyone that has recently (for different values of recently...) communicated with it.

善良天后 2024-09-09 09:31:35

如果您有某种托管交换机,您可能可以连接到它,这将是一个相当优雅的方法。

如果您位于域中,则可以从域控制器获取加入该域的所有计算机的列表。

如果做不到这一点,我能想到的就是挑战/响应(例如 ping 它们)或检测从它们发送的流量(参见 这个问题也许可以作为一个起点?),这两种方法都没有让我觉得优雅。

If you have a managed switch of some kind, you could probably connect to that, that would be a fairly elegant method.

If you're on a domain, you can can get a list of all the machines joined to the domain from the domain controller.

Failing that, all I can think of is either a challenge/response thing (e.g. pinging them) or by detecting traffic sent from them (see this question maybe as a starting point?), neither of which strike me as an elegant approach.

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