User Tools

Site Tools


perl:dns_stuff
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);
}
perl/dns_stuff.txt · Last modified: 2009/08/13 09:57 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki