#!/usr/bin/perl
# # Do not remove the following line, or various programs
# # that require network functionality will fail.
# 127.0.0.1	localhost.localdomain	localhost
# 202.144.239.131	maple0	maple0.mapleora
# 24.68.93.250	me	me.bcgreen.com # some comments 
# 24.68.93.244	really	really.bcgreen.com
open HOSTS, "/etc/hosts";


while( <HOSTS> ) {
	chomp;
	s/#.*//; # delete comments
	if(!  /^[ \t]*$/ ){ # if not blank line
		( $address, @names )  = split /\s+/;
	}
	
        $namefor{$address} = join( " ", @names );
	for ( $counter=0 ; $counter < $#names ; $counter++){
		$ipfor{ $names[$counter] } = $address;
	};
	foreach $name  ( @names ){
		$ip4{ $name} = $address;
	};
}
;


while ( <> ){
	chomp;
	if( /^(\d+\.){3}\d+$/ ){
		if( ! defined($namefor{$_}) ) {
			print" no address $_\n";
		}else{
			printf " the name for %s is %s\n",$_ , $namefor{$_}
		}
	}else{
		if( ! defined($ipfor{$_}) ) {
			print" no hostname $_\n";
		}else{
			printf " the address for %s is %s\n",$_ , $ipfor{$_};
		}
	}
}
