【问题标题】:php mysql loop insert IP Address blockphp mysql循环插入IP地址块
【发布时间】:2014-01-12 10:53:42
【问题描述】:

如何根据 /24 块插入 256 IP。如果 IP 块是 192.168.1.0/24 并且网络是 192.168.1.0 所以我想创建一个循环在 mysql 表中插入 192.168.1.0192.168.1.255 。当我按下时会有一个按钮,它将插入 256 行 0 到 255 .. 请帮我在 php mysql 中做到这一点

if (isset ( $_POST ['doSubmit'] ) && $_POST ['doSubmit'] == 'Submit Details') {
  // Filter POST data for harmful code (sanitize)
  foreach ( $_POST as $key => $value ) {
    $data [$key] = filter ( $value );
  }
  $network = $data [network]; // Is network ip 192.168.1.0
  // Action will go here
}

【问题讨论】:

  • 预期的输入是什么?
  • $data[network] 应该是$data['network']

标签: php mysql ip ip-address


【解决方案1】:

所以我想创建一个循环以将 192.168.1.0 插入 192.168.1.255 mysql表

像这样生成...

foreach(range(0,255) as $val)
{
    $arr[]="192.168.1.".$val;
    //Running a query 255 times here is not a good idea !
}

//$arr now holds all your IPs , you could push it into your SQL Query..

【讨论】:

    猜你喜欢
    • 2014-11-15
    • 2011-02-24
    • 2023-02-22
    • 1970-01-01
    • 2012-06-19
    • 2012-07-10
    • 2015-08-28
    • 2019-08-11
    • 2022-01-07
    相关资源
    最近更新 更多