#!/usr/bin/perl use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use CGI::Simple; use NetAddr::IP; use CommonWeb qw(:ALL);; #file snCalc.cgi little subnet calculator app # Set up the CGI object... my $q = new CGI::Simple; # ... and get query-string params as well as POST params if necessary $q->parse_query_string; # Convenience; saves changing all references to %webvar ##fixme: tweak for handling ); # Just In Case exit 0; # subs sub xrange { my $block = shift; my $masklen = shift; my $data = $block->range; if ($masklen >= 24) { $data =~ s/\b0\.0\.0\./x.x.x./g; } elsif ($masklen >=16) { $data =~ s/\b0\.0\.(\d+\.\d+)/x.x.$1/g; } elsif ($masklen >=8) { $data =~ s/\b0\.(\d+\.\d+\.\d+)/x.$1/g; } return $data; } # xrange() sub getranges { my $masklen = shift; my $ret = ''; my $super; if ($masklen < 8) { $super = new NetAddr::IP "0.0.0.0/0"; } elsif ($masklen < 16) { $super = new NetAddr::IP "0.0.0.0/8"; } elsif ($masklen < 24) { $super = new NetAddr::IP "0.0.0.0/16"; } else { $super = new NetAddr::IP "0.0.0.0/24"; } foreach my $net ($super->split($masklen)) { $ret .= "\t".xrange($net,$masklen)."
\n"; } return $ret; } # getranges()