How to store a list of IPAddresses in eprom ?

I want to ping and check if devices on local network are online or not,

After I retrieve ip addresses i can iterate like this.

IPAddress hosts[] = { IPAddress(192, 168, 1, 2), IPAddress(192, 168, 1, 3), ... };
const int hostsCount = sizeof(hosts) / sizeof(hosts[0]);
...
  for (int i=0; i < hostsCount; hostsCount++) {
    // do something with host[i]
  }

I dont have much experience with cpp or c just learning as i go.

Thank you

An IP address is nothing more than an uint32_t (unsigned long). The class contains a method to convert an IPAddress object to an uint32_t; it also has a constructor that takes an uint32_t instead of the 4 individual values.

The easy way to save to eeprom and retrieve from eeprom are the put() and get() methods.

#include <Ethernet.h>
#include <EEPROM.h>

IPAddress hosts[] = { IPAddress(192, 168, 1, 20), IPAddress(192, 168, 1, 30)};
const int hostsCount = sizeof(hosts) / sizeof(hosts[0]);

void setup()
{
  Serial.begin(57600);

  // where we start to store ip addresses in eeprom
  uint16_t eepromAddress = 0;

  // save to eeprom
  for (uint16_t cnt = 0; cnt < hostsCount; cnt++)
  {
    Serial.println(uint32_t(hosts[cnt], HEX);
    EEPROM.put(eepromAddress, uint32_t(hosts[cnt]));
    eepromAddress += sizeof(uint32_t);
  }

  // retrieve and work with it
  // where the first ip address was stored
  eepromAddress = 0;
  for (uint16_t cnt = 0; cnt < hostsCount; cnt++)
  {
    // retrieve
    uint32_t ipRaw = EEPROM.get(eepromAddress, ipRaw);
    Serial.println(ipRaw, HEX);
    // convert to IPAddress
    IPAddress ipRetrieved(ipRaw);
    // do something with ipRetrieved

    // next eeprom address for next host ip
    eepromAddress+=sizeof(uint32_t);
  }
}

void loop()
{

}

I hope that the comments are clear enough for you to understand. Not that the ip addresses are printed as hex, not decimal.