-2

I want to add IP address from start to end to database such as

IP Address (Start) 192.168.0.0
IP Address (End) 192.168.0.10

So it should add to database like

192.168.0.1
192.168.0.2
192.168.0.3
192.168.0.4
192.168.0.5
192.168.0.6
192.168.0.7
192.168.0.8
192.168.0.9
192.168.0.10

Thanks so much I have no idea.

2 Answers2

2

Quick and dirty, it will take care if the range spreads across octets

$start = '192.168.0.1';
$end = '192.168.1.255';

$startint = ip2long($start);
$endint = ip2long($end);

while ($startint <= $endint) {
 echo long2ip($startint++); // replace echo with your DB insert
}
Christian Bock
  • 441
  • 3
  • 6
0
$start = '192.168.0.';
$x = 1;
while($x < 11)
{
echo $start.$x."<br>"; // create your code to add to table
    $x++;
}

PHPFiddle: http://phpfiddle.org/main/code/g9a4-qxfy

Len_D
  • 1,422
  • 1
  • 12
  • 21