IP address list generator

Here is a simple PHP script for generating a IP address list from IP range. The script contains two files. One file is for data input and one for processing and generating the list.

Demo: http://vrsho.com/demo/iplistgenerator/

First file contains a HTML form for data input(index.html):

[cc lang=”php”]<html>
<form id=’form1′ name=’form1′ method=’post’ action=’ip-list-generator.php’>
<p>
<input name=’textfield’ type=’text’ size=’15’ maxlength=’15’/>

<input name=’textfield2′ type=’text’ size=’15’ maxlength=’15’/>
</p>
<p>
<input type=’submit’ name=’Submit’ value=’Generate’/>
</p>
</form>
</html>[/cc]

Second file generates the list(ip-list-generator.php):

[cc lang=”php”]<?php
$from = $_POST[‘textfield’];
$to = $_POST[‘textfield2’];

$myFile = “ip_list.txt”;
$fh = fopen($myFile, ‘w’);

$arry1 = explode(“.”,$from);
$arry2 = explode(“.”,$to);
$a1 = $arry1[0]; $b1 = $arry1[1]; $c1 = $arry1[2]; $d1 = $arry1[3];
$a2 = $arry2[0]; $b2 = $arry2[1]; $c2 = $arry2[2]; $d2 = $arry2[3];

while( $d2 >= $d1 || $c2 > $c1 || $b2 > $b1 || $a2 > $a1){
if($d1 > 255){
$d1 = 1;
$c1 ++;}

if($c1 > 255){
$c1 = 1;
$b1 ++; }

if($b1 > 255){
$b1 = 1;
$a1 ++; }

fwrite($fh, “$a1.$b1.$c1.$d1\r\n”);
$d1 ++;
}
fclose($fh);
header(‘location: ip_list.txt’);
?>[/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *

*