douxia1988 2013-04-09 02:46
浏览 47
已采纳

拆分IP地址范围后,IP地址将在210937条记录后停止

I have a database of IP ranges and I am using the code below to split the range in to individual IP addresses. This works fine until I get to 210937 records then the code stops spilitting the IP range and starts inserting 0.0.0.0.

I have tried removing some IP addresses but it still stops at the same point even though the IP address is different.

 for ($ip = ip2long($ip1); $ip<=ip2long($ip2); $ip++)
 {
 $lip = long2ip($ip);

Any suggestions would be appreciated.

Ok so here is the full code minus db connection.

  $query1 = "SELECT * FROM masteriplist";
  $result = mysql_query($query1);
  while($row = mysql_fetch_array($result))
  { 

   $ipe = $row['ip_end_range'];
   $ips = $row['ip_start_range'];

   $ip1 = "$ips";
   $ip2 = "$ipe";


   for ($ip = ip2long($ip1); $ip<=ip2long($ip2); $ip++)
    {
    $lip = long2ip($ip);


    mysql_query("INSERT INTO ip_master (ip) VALUES ('$lip')") 
    or die(mysql_error()); 

     }
     }

ok the debugging code returned the following

array(24) { 
  ["id"]=> string(2) "50" 
  ["ip_address"]=> string(12) "85.119.25.27"
  ["ip_start_range"]=> string(0) ""
  ["ip_end_range"]=> string(0) ""
  ...
}
  • 写回答

1条回答 默认 最新

  • dongsuichi6529 2013-04-09 03:08
    关注

    It looks like you're processing a single IP address instead of a range; dealing with both could be done with this:

    if ($row['ip_start_range'] == '' || $row['ip_end_range'] == '') {
        $ip1 = $ip2 = $row['ip_address'];
    } else {
        $ip1 = $row['ip_start_range'];
        $ip2 = $row['ip_end_range'];
    }
    

    Also, you could make it more efficient by moving the ip2long calls outside of the loop:

    $start = ip2long($ip1);
    $stop = ip2long($ip2);
    
    for ($ip = $start; $ip <= $stop; $ip++) {
      // ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c