有没有内置的方法来检查IP地址是否已被占用?
我的软件更改了计算机的 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的网络不使用 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.您可以使用 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.