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('10.2.9.0/29'); $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.
In reply to Re: ip address list
by aaron_baugher
in thread ip address list
by mlebel
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |