/** * convert an IP address into a hex value * * @param string $IP * @return string */ protected function convertIpToHex($host) { if (!isset($host) || empty($host) || !is_string($host)) { static::raiseError(__METHOD__ . '(), $host parameter is invalid!'); return false; } global $ms; $ipv4 = new Net_IPv4(); $parsed = $ipv4->parseAddress($host); // if CIDR contains no netmask or was unparsable, we assume /32 if (empty($parsed->netmask)) { $parsed->netmask = "255.255.255.255"; } if (!$ipv4->validateIP($parsed->ip)) { $ms->throwError(_("Incorrect IP address! Can not convert it to hex!")); } if (!$ipv4->validateNetmask($parsed->netmask)) { $ms->throwError(_("Incorrect Netmask! Can not convert it to hex!")); } if (($hex_host = $ipv4->atoh($parsed->ip)) == false) { $ms->throwError(_("Failed to convert " . $parsed->ip . " to hex!")); } if (($hex_subnet = $ipv4->atoh($parsed->netmask)) == false) { $ms->throwError(_("Failed to convert " . $parsed->netmask . " to hex!")); } return array('ip' => $hex_host, 'netmask' => $hex_subnet); }