#!/usr/bin/perl


use Socket;

$ipaddr = join ("",@ARGV);

if(!$ipaddr){
	print("Usage: $0 192.168.0.10-38\n");
}

&make_pole($ipaddr);

foreach $h (@hosts){
#print "$h\n";

 if(($name) = gethostbyaddr(inet_aton($h), AF_INET)){
  print "$name $h\n";
 }

}

#####################################
sub make_pole {
$line = $_[0];

    if ($line != /#/){
	if ($line =~ /-/){
	    @tmp = split /-/, $line;
	    @bip = split /\./,$tmp[0];
	    @eip = split /\./,$tmp[1];
	    }
	    else {
	    @bip =split /\./, $line;
	    @eip =split /\./, $line;
	    }
	    $a1 = $bip[0];
	    $b1 = $bip[1];
	    $c1 = $bip[2];
	    $d1 = $bip[3];
	    $num = @eip;
	    if ($num == 1){
		$a2 = $bip[0];
		$b2 = $bip[1];
	        $c2 = $bip[2];
	        $d2 = $eip[0];
		} elsif ($num == 2){
		$a2 = $bip[0];
		$b2 = $bip[1];
	        $c2 = $eip[0];
	        $d2 = $eip[1];
		} elsif ($num == 3){
		$a2 = $bip[0];
		$b2 = $eip[0];
	        $c2 = $eip[1];
	        $d2 = $eip[2];
		} elsif ($num == 4){
		$a2 = $eip[0];
		$b2 = $eip[1];
	        $c2 = $eip[2];
	        $d2 = $eip[3];
		}
		
		check_end();
		$aend = $a2;
		while ($a1 <= $aend){
		    while ($b1 <= $bend){
			while ($c1 <= $cend){
			    while ($d1 <= $dend){
				push (@hosts, "$a1.$b1.$c1.$d1");
				$d1+=1;
				check_end();
			    }
			$c1+=1;
			$d1=0;
			}
		    $b1+=1;
		    $c1=0;
		    }
		$a1+=1;
		$b1=0;
		}
	}
    }
    
sub check_end {
    if(($a1==$a2) && ($b1==$b2) && ($c1==$c2)) {
	$dend=$d2;
    } else {
	$dend=255;
    }
    if(($a1==$a2) && ($b1==$b2)){
	$cend=$c2;
    } else {
	$cend=255;
    }
    if($a1==$a2){
	$bend=$b2;
    } else {
	$bend=255;
    }
}

1;

