例子如下:
#!/usr/bin/perl -w
use strict;
use Net::DNS;
# Look up a host's addresses.
my $res = Net::DNS::Resolver->new;
my $query = $res->search("");
if ($query) {
foreach my $rr ( grep { $rr->type eq "A" } $query->answer ) {
print $rr->address, "\n";
}
}
else {
warn "query failed: ", $res->errorstring, "\n";
}
# Find the nameservers for a domain.
my $res = Net::DNS::Resolver->new;
my $query = $res->query( "qq.com", "NS" );
if ($query) {
foreach my $rr ( grep { $_->type eq 'NS' } $query->answer ) {
print $rr->nsdname, "\n";
}
}
else {
warn "query failed: ", $res->errorstring, "\n";
}
# Find the MX records for a domain.
my $res = Net::DNS::Resolver->new;
my $name = "qq.com";
my @mx = mx( $res, $name );
if (@mx) {
foreach my $rr (@mx) {
print $rr->preference, " ", $rr->exchange, "\n";
}
}
else {
warn "Can't find MX records for $name: ", $res->errorstring, "\n";
}
# Print a domain's SOA record in zone file format.
my $res = Net::DNS::Resolver->new;
my $query = $res->query( "qq.com", "SOA" );
if ($query) {
( $query->answer )[0]->print;
}
else {
print "query failed: ", $res->errorstring, "\n";
}
很简单,每个注释下的内容可以独立出来使用。
阅读(2492) | 评论(0) | 转发(1) |