Welcome Guest, Not a member yet? Register   Sign In
IP Range Generation
#1

[eluser]echoDreamz[/eluser]
Code:
$start = explode('.', $_POST['ipRange1']);
    $end = explode('.', $_POST['ipRange2']);

    /**
     * Final output...
     */
    $a = 0;
    $b = 0;
    $c = 0;
    $d = 0;
    $total = 0;
    
    // First segment
    for ($a = $start[0]; $a < 1 + $end[0]; $a++)
    {
        // Second segment
        for ($b = $start[1]; $b < 1 + $end[1]; $b++)
        {
            // Third segment
            for ($c = $start[2]; $c < 1 + $end[2]; $c++)
            {
                // Fourth segment
                for ($d = $start[3]; $d < 1 + $end[3]; $d++)
                {
                    $total++;
                    echo "{$a}.{$b}.{$c}.{$d}<br />";
                }
            }
        }
    }

The above works fine for ranges like 192.168.1.1 - 192.168.2.254 however for items like 192.168.1.10 - 192.168.2.15 it only lists the 6. I see why it is doing this, I just cant find a way around this.

Thank for the help!
#2

[eluser]danmontgomery[/eluser]
Code:
function test() {
    $ip1 = ip2long('192.168.1.10');
    $ip2 = ip2long('192.168.2.15');
        
    while($ip1 <= $ip2) {
        echo long2ip($ip1++).'<br/>';
    }
}
#3

[eluser]echoDreamz[/eluser]
Yes, it hit me about about 10 minutes ago lol.




Theme © iAndrew 2016 - Forum software by © MyBB