2

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

user664939
  • 1,977
  • 2
  • 20
  • 35

2 Answers2

4

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.

Donut
  • 110,061
  • 20
  • 134
  • 146
4

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.

Community
  • 1
  • 1
Phil
  • 6,561
  • 4
  • 44
  • 69
  • I think that the ping class should suffice (the other machines on the network should respond), but this looks like a more in-depth alternative if I need it. Thanks and +1. – user664939 Jun 07 '11 at 17:01
  • A ping would suffice for most situations, I just offered an answer for completeness (and because I was curious myself). – Phil Jun 07 '11 at 17:05