calculateLastIpAddress method

List<int> calculateLastIpAddress()

Implementation

List<int> calculateLastIpAddress() {
  int fill = 0;
  List<int> octets = List<int>.filled(4, fill, growable: false);

  // Determine host bits
  int hostbits = 32 - netmask;
  // Set all host bits to 1
  int invertor = 0;
  for (int i = 0; i < hostbits; i++) {
    invertor += pow(2, i).toInt();
  }
  int lastAddress = address | invertor;
  //substract 1 to get last address instead of broadcast address
  lastAddress--;

  octets[0] = (lastAddress & (255 << 24)) >> 24;
  octets[1] = (lastAddress & (255 << 16)) >> 16;
  octets[2] = (lastAddress & (255 << 8)) >> 8;
  octets[3] = lastAddress & (255);
  return octets;
}