Hello all,
I have multiple rabbits on a local network without DHCP. Currently, each is assigned a static IP (from x.x.x.10 through x.x.x.15), but the IP is hard-coded. I change a #define at the beginning of my program to select the rabbit, and a bunch of #ifdefs are used to assign the right static IP and bring up all the interfaces and sockets. This works, but it is tedious when I need to update all of them, because I must flash one, then change the #define, then flash the next one, then change the #define… etc.
Instead, I would prefer a situation in which each rabbit tries to go for x.x.x.10, and if it finds an address conflict there, then go for 11, then 12, etc… Basically, to make each Rabbit function as its own mini-DHCP for those few addresses, with the end result being that the rabbits are assigned the next available address within a small given range.
Is there a way to check if a local IP address is already occupied?
Cheers,
Michael
Ping the local adress?
If you get a reply, ping the next one till you dont get a response anymore.
I appreciate the reply.
I don’t think that will work though, because (as I understand it) you need to have an IP address already to ping one. So I’d still have to assign each Rabbit a starting IP, and then I’m at the same problem – 5 rabbits, 1 static ip.
I’m a n00b programmer though, so if this is not true, can you help me by explaining how to have a Rabbit ping something without first assigning it an IP?
Yes you are right, I wasn’t thinking straight.
What you can do perhaps, is keep x.x.x.10 open. Then when a new rabbit gets on the network, assign that rabbit to x.x.x.10. The rabbit will then start to ping the other IP adresses until it doesn’t get a response, then change its IP adress to that IP adress.
Its been a while since I have worked with rabbit IP, but can the rabbit change its IP adress on the fly? Or is it hardcoded in the program? I think I only worked with hardcoding the IP adress through a #define as you have mentioned.