in reply to Generation of sequential IP addresses for Class B network

You have not declared the variable, $_second_octet_num variable. I don't know how your program is generating 192.168.1.1 to 192.168.1.254 without that.

Here I am giving the code for generating a IP address from 192.168.1.1 to 192.168.254.254. You can adjust the code according to your situation.

#!/usr/bin/perl use strict; use warnings; my $first_octet_num = "1"; my $ip_address; foreach (1..254) { foreach (1..255) { if ($_ <= 254) { $ip_address = join ('.', 192,168,$first_octet_num,$_); print "$ip_address\n"; } else { $first_octet_num++; } } }

One more information for you, IP address start with 192, it's not class B. It's class C. Reference here.

Replies are listed 'Best First'.
Re^2: Generation of sequential IP addresses for Class B network
by ikegami (Patriarch) on Jun 24, 2009 at 14:13 UTC

    One more information for you, IP address start with 192, it's not class B. It's class C.

    The size of a network is no longer determined by the first octet.

    The private use space at 192.168 is large enough to host a class B (/16) network if desired. Of course, the OP is clearly requesting a series of class C (/24) networks based on his requirements. Odd, since he obviously sees it at one large network.

Re^2: Generation of sequential IP addresses for Class B network
by perlpal (Scribe) on Jun 24, 2009 at 11:20 UTC
    Really sorry , clumsy at pasting the code. I dont know how i forgot to paste the declaration.

    Thanks for the code though, i managed to tailor it to my needs.

    Cheers!