diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 15:54:22 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2018-04-19 16:08:35 +0300 |
commit | c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a (patch) | |
tree | bfdaf4003628135622ff7373d8b15cffedc77ff0 | |
parent | 967317a3d5c0ced836d8b6217288cd04819ddc36 (diff) | |
download | acmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.gz acmeman-c7c75b0cca25ecacad0ba2dfe7c41db836a0b17a.tar.bz2 |
Resolve CNAMES recursively
This complements b2e15909.
-rwxr-xr-x | acmeman | 24 |
1 files changed, 21 insertions, 3 deletions
@@ -1,4 +1,7 @@ -#!/usr/bin/perl +#!/bin/sh +#!-*-perl-*- +eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' + if 0; # not running under some shell # Copyright (C) 2017, 2018 Sergey Poznyakoff <gray@gnu.org> # # This program is free software; you can redistribute it and/or modify @@ -893,7 +896,7 @@ sub resolve { unless ($res) { $res = new Net::DNS::Resolver(); } - my $q = $res->query($host, 'A'); + my $q = $res->query($host,'ANY'); unless ($q) { if ($res->errorstring eq 'NXDOMAIN') { debug(1, "$host: no such host"); @@ -905,7 +908,22 @@ sub resolve { } return (); } - return map { $_->rdatastr } grep { $_->type eq 'A' } $q->answer; + my %res; + my %cnames; + my @answer = $q->answer(); + while (my $ans = shift @answer) { + if ($ans->type eq 'A') { + $res{$ans->rdatastr} = 1; + } elsif ($ans->type eq 'CNAME') { + unless ($cnames{$ans->owner}) { # Avoid eventual loops + $cnames{$ans->owner} = 1; + if (my $q = $res->query($ans->cname, 'A')) { + push @answer, ($q->answer()); + } + } + } + } + keys %res; } sub myip { |