interger to I P address

Mike Damm mike at damm.com
Wed Aug 27 13:08:27 CDT 2008


The PHP way:
echo long2ip('1089055123');

Boyd, Benjamin R wrote:
> The PHP way:
> function convertIntegerToIpv4($integer) 
> {
>   $max_value = pow(2,32);           //4,294,967,296 
>   $bug_fix = 0;
>   settype($integer, float);
>
>   if($integer > 2147483647) $bug_fix = 16777216;
>     
>   if(is_numeric($integer)) 
>   { 
>     if ($integer >= $max_value || $integer < 0)
>     {
>       return ('Not a valid IPv4 integer');
>     }
>     $ip = (sprintf("%u.%u.%u.%u",
>             $integer / 16777216,
>             (($integer % 16777216) + $bug_fix) / 65536,
>             (($integer % 65536) + $bug_fix / 256) / 256,
>             ($integer % 256) + $bug_fix / 256 / 256
>             )
>           ); 
>     return($ip);
>   }
>   else {
>      return('');
>   }
> }
>   





More information about the NANOG mailing list