I'm trying to write a function that tells you if an IP address is in a classless subnet. First of all, has any one already written this code? If not, I'm having trouble with the regex's. Is there an easy way to match a range of numbers like 128-255?
I've written it like this, taking advantage of the fact that 255 is the highest possible number:
if ($number =~ /12/ ||$number =~ /1[3-9]\d/ ||$number =~ /2\d\d\/)
$match = 1;
There must be a better way.
For the more general subnetting problem I'm thinking I probably need to work in binary and doing the AND's and OR's etc. does anyone know of some example Perl code.