Bueno al final lo hize yo,
Esta medio mounstruoso y es optimizable, pero funciona, retorna False si no es valida la IP
Código PHP:
function ValidarIP($IP) ////////////////////////// validador de IP #################
{
$IPValida = false;
$IP = str_replace(" ","",$IP);
/*
$largo = strlen($IP);
$A = array ($IP);
while($A[i] <= $largo )
{
i++;
}
*/
// if(str_count($IP)=)
$IP = str_replace("/",".",$IP);
list($oct1,$oct2,$oct3,$oct4,$Red) = split('[.]',$IP);
$oct1=trim($oct1);
$oct2=trim($oct2);
$oct3=trim($oct3);
$oct4=trim($oct4);
$Red=trim($Red);
if (substr_count($IP,".") == 4) //con red
{
{
if
(
($Red == 32) ||
($Red == 16) ||
($Red == 8) ||
($Red == 4) ||
($Red == 2)
)
{
if ($oct1 >= 0 )
{
if($oct1 < 256)
{
if ($oct2 >= 0 )
{
if($oct2 < 256)
{
if ($oct3 >= 0 )
{
if($oct3 < 256)
{
if ($oct4 > 0 )
{
if($oct4 < 255)
{
$IPValida = true;
}
}
}
}
}
}
}
}
}
}
}
else
{
if (substr_count($IP,".") == 3) //sin Red
{
if
(
(is_numeric($oct1) == true) &&
(is_numeric($oct2) == true) &&
(is_numeric($oct3) == true) &&
(is_numeric($oct4) == true )
)
{
if ($oct1 >= 0 )
{
if($oct1 < 256)
{
if ($oct2 >= 0 )
{
if($oct2 < 256)
{
if ($oct3 >= 0 )
{
if($oct3 < 256)
{
if ($oct4 > 0 )
{
if($oct4 < 255)
{
$IPValida = true;
}
}
}
}
}
}
}
}
}
}
}
return $IPValida;
}