Skip to main content


I wanted a quick way to convert 255.255.255.252 -> 30 and other netmasks... this works!

$mask =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ or next;
$cidr = 32 - (log(256-$1)+log(256-$2)+log(256-$3)+log(256-$4)) / log(2);

submitted by /u/sfxsf
[link] [comments]