Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: IP troubles

by jwest (Friar)
on Dec 18, 2001 at 02:07 UTC ( #132690=note: print w/ replies, xml ) Need Help??


in reply to IP troubles

Does this fit the bill?

use strict; use warnings; use Net::Netmask; while (<>) { chomp; s/;/:/; my $block = new Net::Netmask($_); if (not $block) { warn "Bad CIDR specification"; next; } my @ip = $block->enumerate(); # Remove the network and gateway addresses. shift(@ip); shift(@ip); # Remove the broadcast address. pop(@ip); for my $ip (@ip) { print $ip, "\n"; } }

--jwest

-><- -><- -><- -><- -><-
All things are Perfect
    To every last Flaw
    And bound in accord
         With Eris's Law
 - HBT; The Book of Advice, 1:7


Comment on Re: IP troubles
Download Code
Re: Re: IP troubles
by toadi (Chaplain) on Dec 18, 2001 at 14:41 UTC
    How should the data look as input?

    --
    My opinions may have changed,
    but not the fact that I am right

      Sorry - I should have specified that. As per your example, you can enter it as:

      192.168.1.0;255.255.255.0

      Or, since we're using Net::Netmask:

      192.168.1.0/24
      192.168.1.0:255.255.255.0
      192.168.1 - which assumes a /24 block
      192.168 - which assumes a /16 block
      192 - which assumes a /8 block
      192.168.1/24
      192.168/16
      etc.

      Net::Netmask is particularly smart about parsing these things, so it's a nice tool to leverage for this type of work.

      --jwest

      -><- -><- -><- -><- -><-
      All things are Perfect
          To every last Flaw
          And bound in accord
               With Eris's Law
       - HBT; The Book of Advice, 1:7
      

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://132690]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-07-04 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls