Just another Perl shrine | |
PerlMonks |
Re: regex for classless IP subnetsby kal (Hermit) |
on Mar 24, 2003 at 19:57 UTC ( [id://245516]=note: print w/replies, xml ) | Need Help?? |
If you want to avoid the overhead of a full module, you could probably to it with two functions. First, something to convert IP addresses into integers, like:
Then, you just want to compare the network parts of the IP address with the network address. So, obviously you need to create the netmask (i.e., /16 is (2**16)-1, I think?), and then just compare the numbers, i.e.:
You could obviously wrap that in a common function, perhaps something like:
Or something (much more error checking would of course be required ;). That's off the bat, unfortunately I don't have access to a Perl right now :/ But, I'm pretty sure it's not supposed to be sufficiently complex to require a regex - remember, C programmers use IP addresses (socket.h), so it's can't be very difficult.
In Section
Seekers of Perl Wisdom
|
|