我可以通过Perl确定给定的“主机名”是否为CNAME

时间:2011-06-03 22:24:23

标签: perl dns cname

在工作中,我有类似的东西......

$ host www.something.com
www.something.com is an alias for some.other.address
some.other.address is an alias for one.more.address
one.more.address has address xxx.xxx.xxx.xxx

我想要一种方法,在Perl中放入www.something.com并确定它是否是CNAME,A记录等。

1 个答案:

答案 0 :(得分:8)

use Net::DNS qw();
my $query = Net::DNS::Resolver->new->search('conferences.yapceurope.org');

if ($query) {
    foreach my $rr ($query->answer) {
        next unless 'CNAME' eq $rr->type;
        print $rr->cname;
    }
} else {
    warn sprintf "query failed: %s\n", $res->errorstring;
}