User Tools

Site Tools


perl:dns_stuff

This is an old revision of the document!


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.1242310969.txt.gz · Last modified: 2009/05/14 07:22 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki