If I want to have IP addresses like: 1.1.1.0/8 or 203.10.22.19 to 203.10.22.255 is there any shortcut way to put this in the @array?
1.1.1.0/8 is not a valid network address, by the way. Perhaps you want 1.0.0.0/8?
Here's a way to produce a list of all IP addresses in a network, given it's subnet address and mask (in the form a.b.c.d/e)
sub get_ips { my $subnet_specification=shift; # Get t +he subnet specification. my ($network, $mask)=split(/\//, $subnet_specification); + # Break it into a subnet and mask. my @subnet_array=split/\./,$network; # Spli +t the network into individual octets. my $subnet_value=$subnet_array[0]*0x1000000+$subnet_array[1]*0x100 +00+$subnet_array[2]*0x100+$subnet_array[3]; # $subnet_value now contains a 32-bit value corresponding to the n +etwork address given. # Now calculate the top end of the subnet. my $top_address=$subnet_value+(2**(32-$mask)-1); # We now have the first and last addresses required. Produce a lis +t of all addresses in between, in dotted-decimal format. my @return_value; # Holds the array + of addresses we are returning for (my $address=$subnet_value; $address<=$top_address; $address++ +) { my @octets=(int($address/0x1000000)%0x100, int($address/0x1000 +0)%0x100, int($address/0x100)%0x100, $address%0x100); push(@return_value, join(".", @octets)); # +Assemble it into a dotted-decimal form and add it to the returned arr +ay. } return @return_value; }
Just call get_ips("192.168.0.0/24");

In reply to Re: Net::Ping issues by leighsharpe
in thread Net::Ping issues by chris_henderson

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.