Here is my own code (derived from Re: Checking IP's with an IP/mask) to generate the list, without using Net::Netmask. It also seems to work for supernetted blocks through at least a /8 (just finished that test-16,777,216 addresses and code feels fine). Included is my test code for a block (in this case, 192.168.1.32/28). The code also makes allowances for if you want to generate the list with/without the network, gateway, and/or broadcast addresses included.

(Might could use some clean-up by way of making sure that $nonetwork, $nogateway, and $nobroadcast are only set either 0 or 1.)

#!/usr/bin/perl -w -- use strict; # # Set to 1 to remove from generated list, 0 to leave in # my $nonetwork = 1; my $nogateway = 1; my $nobroadcast = 1; my $block = '192.168.1.32'; my $cidr = 28; my $machines = 2**(32 - $cidr); my $lip = unpack("N", pack("C4", split(/\D/, $block, 4))); # # Assumes gateway is at beginning, not end, of block # for (my $i = ($nonetwork + $nogateway); $i < ($machines - $nobroadcast); $i++) my $res = $lip + $i; print(join('.', unpack("C4", pack("N", $res))), "\n"); }

Comments? Questions? Hope this helps.

Update: Noted in several of the posts afterwards that the input format was discussed. In my code above, I believe significate modification would likely be required to use netmask rather than CIDR notation.


In reply to Re: IP troubles by atcroft
in thread IP troubles by toadi

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.