#!/usr/bin/perl
$args = $#ARGV + 1;
if ($args < 1) {  
    #print "Wrong entry. Please enter your full name.\n";  
    exit;  
}  

sub uniq {
    my %seen;
    grep !$seen{$_}++, @_;
}

$ipstr = $ARGV[0];
$action = $ARGV[1];  

my @ips = split(/\s+/, $ipstr);
my @realips = ();
foreach my $i (@ips) 
{
    my @ip = split('-', $i);
    if(!$ip[1]) {
        push(@realips, $ip[0]);
        #print "empty end and contiune\n";
        next;
    }

    my @tmp = split(/\./, $ip[0]);
    $start = $tmp[3];
    $end = $ip[1];
    for($start; $start <= $end; $start ++){
        $newip = "$tmp[0].$tmp[1].$tmp[2].$start";
        push(@realips, $newip);
        #print "$newip \n";
    }
}

my $ipsize = @realips;
if($ipsize == 0){
    exit;
}

@acls = ();
@has  = ();
@tcps = ();
$count = 0;
my @u_realips = uniq(@realips);


if($action eq 'showip') {
    print $_, "," for @u_realips;
    exit;
}


foreach my $ip (@u_realips)
{
    push(@acls, "acl ip$count myip $ip\n");
    push(@has, "http_access allow ip$count\n");
    push(@tcps, "tcp_outgoing_address $ip ip$count\n");
    $count++;
}

print "\n";
foreach $acl (@acls) {
     print $acl;
}
print "\n";
foreach $ha (@has) {
     print $ha;
}
print "\n";
foreach $tcp (@tcps) {
     print $tcp;
}
print "\n";
