Hi,

Thursday, January 23, 2003, 2:10:05 PM, you wrote:

rsn>     I need a way to add a range of IPaddress to a databases the
rsn>     example below work as long as the last numbers in the IPaddress
rsn>     are equal length like three numbers or two or one. If the first
rsn>     IPaddress has 1 number and the second has two or three numbers the
rsn>     script will not work.
    
rsn>     $ip1=230.234.234.4    This will work
rsn>     $ip2=230.234.234.9

rsn>     $ip1=230.234.234.4     This will not work
rsn>     $ip2=230.234.234.25

rsn>     $ip1=230.234.234.25    This will not work
rsn>     $ip2=230.234.234.126


    
rsn>          $ip1=trim($ip1);
rsn>          $ip2=trim($ip2);
rsn>         $ip = $ip1;
rsn>         while ($ip <= $ip2){ 
rsn>     $query = "insert into ipaddress(ip)values ('$ip')";
rsn>         $Result = safe_query($query);
rsn>         $ip++;
rsn>         }

  

rsn> -- 
rsn> Best regards,
rsn>  rdkurth                          mailto:[EMAIL PROTECTED]

you will need to split the last bit and treat it as a number to increment it
properly, something like

list($ip4,$ip3,$ip2,$ip1) = split('.',$ip1);
list$ip8,$ip7,$ip6,$ip5) = split('.',$ip2);
$ip = intval($ip1);
$endip = intval($ip5);
while($ip < $endip){
          $storeip = $ip4.'.'.$ip3.'.'.$ip2.'.'.$ip;
          //store it
          $ip ++;
}
There are probably other ways but you get the idea
-- 
regards,
Tom


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

Reply via email to