• Модуль: security
  • Путь к файлу: ~/bitrix/modules/security/classes/general/system_information.php
  • Класс: CSecuritySystemInformation
  • Вызов: CSecuritySystemInformation::isIpValid
static function isIpValid($ip, $allowPrivate = false, $allowRes = false)
{
	// ToDo: what about PHP filters?
	if (ip2long($ip) === false)
		return false;

	$ipOctets = explode('.', $ip);
	if (!$allowPrivate)
	{
		// php/ext/filter/logical_filters.c, FILTER_FLAG_NO_PRIV_RANGE
		if ($ipOctets[0] == 10)
			return false;

		if ($ipOctets[0] == 172 && $ipOctets[1] >= 16 && $ipOctets[1] <= 31)
			return false;

		if ($ipOctets[0] == 192 && $ipOctets[1] == 168)
			return false;

	}

	if (!$allowRes)
	{
		// php/ext/filter/logical_filters.c, FILTER_FLAG_NO_RES_RANGE
		if ($ipOctets[0] == 0)
			return false;

		if ($ipOctets[0] == 100 && $ipOctets[1] >= 64 && $ipOctets[1] <= 127)
			return false;

		if ($ipOctets[0] == 169 && $ipOctets[1] == 254)
			return false;

		if ($ipOctets[0] == 192 && $ipOctets[1] == 0 && $ipOctets[2] == 2)
			return false;

		if ($ipOctets[0] == 127 && $ipOctets[1] == 0 && $ipOctets[2] == 0)
			return false;

		if ($ipOctets[0] >= 224 && $ipOctets[0] <= 255)
			return false;
	}

	return true;
}