XP is just a number | |
PerlMonks |
Iterating through all IP addresses in a CIDRby grinder (Bishop) |
on Nov 04, 2003 at 13:53 UTC ( [id://304414]=perlquestion: print w/replies, xml ) | Need Help?? |
grinder has asked for the wisdom of the Perl Monks concerning the following question: I'm trying to be Lazy and find a module that will iterate through an arbitrary CIDR for me. For example: 172.18.0.0/18 My first impulse was to dig out Net::CIDR and use cidr2octets but that only returns the leading octets representing the netblock in question. E.g., cidr2octets("172.19.1.0/24") returns 172.19.1. So then I turned to CPAN and found Net::IPv4Addr but, at a first brief glance, that doesn't help me. I'm sure there's a module that does what I want, I just don't know its name... To be precise, I want something that takes something like 172.21.3.128/30 and returns 172.21.3.128 Thanks for any pointers (or code :) Update: NetAddr::IP is indeed the ticket (so I guess patching Net::CIDR isn't necessary, although I will write to Sam suggesting a SEE ALSO item in the documentation of Net::CIDR). For those following along at home, given an array of CIDR netblocks in @cidr, the following code will print all the IP addresses. Short, sharp and sweet.
Back to
Seekers of Perl Wisdom
|
|