in reply to Re: gethostbyname() and www prefix
in thread gethostbyname() and www prefix
You can also do it like this to be a trifle more complete:
use Net::DNS; $res = new Net::DNS::Resolver; warn "Net::DNS error $@\n" if $@; # on some systems without the required config files you will need to # direct Net::DNS to your DNS nameserver(s) or it will timeout $res->nameservers( $prinary_nameserver_ip_address, $secondary... ) if +$res; sub dns_query { return undef unless $res; my $domain = shift; $packet = $res->send($domain, 'MX') or warn $res->errorstring; return 1 if $packet->header->ancount; my $packet = $res->send($domain, 'A') or warn $res->errorstring; return 1 if $packet->header->ancount; return 0; } print "OK DNS $domain" if dns_query($domain);
Kanji notes my slack duplication of identical code. It is more maintainable to do this:
sub dns_query { return undef unless $res; my $domain = shift; for my $dns ( 'MX', 'A' ) { $packet = $res->send($domain, $dns ) or warn $res->errorstring +; return 1 if $packet->header->ancount; } return 0; }
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|