Here's a quick function of the top of my head. I'm not sure if
x.x.0.x or x.0.x.x are valid IP addresses. Adjust as necessary.

<?
function cidr($initial_ip, $net_prefix=32) {
  $octet=explode(".",$initial_ip);
  $num_ips=pow(2,(32-$net_prefix));
  $ip_list[]=implode(".",$octet);
  for ($i=1;$i<$num_ips;$i++) {
    if ($octet[3]<256) {
        $octet[3]++;
    }
    if ($octet[3]==256) {
      $octet[2]++;
      $octet[3]=0;
    }
    if ($octet[2]==256) {
      $octet[1]++;
      $octet[2]=0;
    }
    if ($octet[1]==256) {
      $octet[0]++;
      $octet[1]=0;
    }
    if ($octet[0]>255) {
      echo "First octet of IP address cannot exceed 255";
      return false;
    }
    $ip_list[]=implode(".",$octet);

  }
  return $ip_list;

}

$arr=cidr("192.168.1.0",23);
echo "<pre>";
print_r($arr);
echo "</pre>";


?>



--- Rob Lacey <[EMAIL PROTECTED]> wrote:
> does anyone know of a class that is able to extrapolate a list of
> IPs given an 
> address in cidr notation. I have used the Net::Netmask module in
> perl, so I 
> was just wondering if there was a PHP equivalent.
> 
> Thanks
> 
> Rob
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


=====
Mark Weinstock
[EMAIL PROTECTED]
***************************************
You can't demand something as a "right" unless you are willing to fight to death to 
defend everyone else's right to the same thing.
***************************************

__________________________________
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
http://calendar.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to