use Socket;
 
sub lookup {
	my ($a) = @_;
	return is_ip($a) ? ip2host($a)||$a : host2ip($a)||$a;
}
 
sub is_ip { $_[0] =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/ }
 
sub ip2host {
	my ($a) = @_;
	return gethostbyaddr(inet_aton($a), AF_INET) || undef;
}
 
sub host2ip {
	my ($a) = @_;
	my $hrec = (gethostbyname($a))[4] or return undef;
	return inet_ntoa($hrec);
}