Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: ip address list

by aaron_baugher (Curate)
on Jan 19, 2012 at 17:12 UTC ( #948821=note: print w/ replies, xml ) Need Help??

in reply to ip address list

So you want to skip the first two addresses, then print up to the broadcast address, removing the netmask. The simplest way would be to increment the address twice before your loop. Then I'd probably use split to remove the netmask portion, though you could certainly use a regex. I tend to use split when I'm thinking "get everything before a certain character". So:

my $ip = NetAddr::IP->new(''); $ip++; # skip network address $ip++; # skip presumed gateway address while( $ip < $ip->broadcast ){ my $iponly = (split '/', $ip++)[0]; #get part before first /, then inc +rement the ip print "$iponly\n"; }

Looks like you could also use NetAddr::IP's functionality to get the address by itself, as in $ip->addr.

Aaron B.
My Woefully Neglected Blog, where I occasionally mention Perl.

Comment on Re: ip address list
Download Code
Replies are listed 'Best First'.
Re^2: ip address list
by mlebel (Hermit) on Jan 19, 2012 at 17:57 UTC
    That was it Aaron B. Thank you very much, it worked as expected. Thank you to all of you who helped me resolve this problem! Marc

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2016-05-05 05:31 GMT
Find Nodes?
    Voting Booth?