Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I determine if a given "hostname" is a CNAME via Perl

Tags:

perl

dns

cname

At work I have something like this...

$ 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

I would like a way, in Perl to put in www.something.com and determine if it's a CNAME, A record, etc.

like image 906
gdanko Avatar asked Feb 23 '23 23:02

gdanko


1 Answers

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;
}
like image 185
daxim Avatar answered Apr 06 '23 05:04

daxim