There's no such thing as class B anymore. Subnets are divided quite arbitrarily. But let's say you divided 192.168.0.0/16 into 256 nets of size /24:

use NetAddr::IP (); my @hosts; foreach (0..255) { my $net_addr = NetAddr::IP->new("192.168.$_.0/24"); my $net_broadcast = $net_addr->broadcast(); push(@hosts, $net_addr->addr()) while ++$net_addr != $net_broadcast; } print("$_$/") foreach @hosts;

Or if flexibility is not needed:

my @hosts = map { my $pre = "192.168.$_."; map { $pre.$_ } 1..254 } 0..255;

A more efficient version:

my @hosts; foreach (0..255) { my $pre = "192.168.$_."; foreach (1..254) { push(@hosts, $pre.$_); } }

Update: Here's the provided glob solution adjusted to also provide 192.168.0.{1-254} and 192.168.255.{1-254}:

my $octet = join(',', 1..254); my @hosts = glob("192.168.{0,$octet,255}.{$octet}");

In reply to Re: Adding an Entire Class B IP Range to an Array by ikegami
in thread Adding an Entire Class B IP Range to an Array by Dru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.