有没有内置的方法来检查IP地址是否已被占用?

发布于 2024-11-14 13:59:28 字数 79 浏览 1 评论 0原文

我的软件更改了计算机的 IP,但与其他设备发生冲突。是否有内置方法可以在设置 IP 地址之前检查 IP 地址是否已被占用?

谢谢

My software changes the IP of a computer, but I am coming into conflicts with other devices. Is there a built-in way to check if an IP address is already occupied/taken before setting it?

Thanks

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

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

发布评论

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

评论(2

美人如玉 2024-11-21 13:59:28

如果您的网络不使用 DHCP 并且确实需要手动分配 IP 地址,您可以尝试使用 System.Net.NetworkInformation.Ping 查看网络上的主机是否响应。

If your network doesn't use DHCP and IP addresses really do need to be manually assigned, you could try using the System.Net.NetworkInformation.Ping class to see if a host on the network responds.

飘逸的'云 2024-11-21 13:59:28

您可以使用 System.Net.NetworkInformation.Ping 类,如 Donut 建议的那样,但并非所有设备都会响应 Ping。但是,任何具有 IP 地址的设备都会响应 ARP 请求(如果它们是)与网络正常通信。

如果您能找到一种方法来发送 ARP 请求,其中显示“谁拥有 IP 地址 xxx.xxx.xxx.xxx?”当您收到响应时,您就知道其他人拥有该 IP 地址。我个人不知道如何做到这一点,但您可以尝试查看这个问题有关如何访问 ARP 信息的信息。

另外,可能是一个有用的资源。

You could use the System.Net.NetworkInformation.Ping class, as Donut suggested, but not all devices will respond to Pings. However, any device with an IP address will respond to ARP requests if they are communicating with the network properly.

If you can find a way to send out an ARP request that says "Who has IP address xxx.xxx.xxx.xxx?" and you get a response, then you know someone else has that IP address. I personally don't know how to do that off the top of my head, but you could try looking at this question for information on how to access ARP information.

Also, this might be a useful resource.

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