Great Circle Associates Majordomo-Users
(August 1997)
 

Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: Re: Help finding which address...?
From: D . Thomas @ vthrc . uq . edu . au (Danny Thomas)
Date: Mon, 4 Aug 1997 19:18:15 +1000
To: majordomo-users @ GreatCircle . COM

>Anybody know of a tool/script that will run through the contents of a list
>and check the MX records of all of them??

well you might be able to adapt the following fragments which are run by my
slightly hacked version of sendmail. Every error situation is run through a
deliver script, which for bounces tries to diagnose the cause (eg reversed
uk addresses, IP addresses sans '[' ']', etc) and present it in a more
user-understandable form:

  REPORTING on the following email address:
      'public@lwwdc.gov.au'

  ERROR!
  domain: 'lwwdc.gov.au'
           ^^^^^
  I reckon THAT is the rightmost mistake
  (but something could be missing to its' immediate right)

maybe this capability is the embryonic MJ2 ?

while I used to use dig output I now utilize the Net::DNS module
[adjust with of mail window; I hope it's not hard-wrapped]

my %RR_FIELDS =
(
    A      => [ "address"
],
    AAAA   => [ "address"
],
    AFSDB  => [ "subtype", "hostname"
],
    CNAME  => [ "cname"
],
    EID    => [ "rdlength", "rdata"
],
    HINFO  => [ "cpu", "os"
],
    ISDN   => [ "address", "sa"
],
    LOC    => [ "version", "size", "horiz_pre", "vert_pre", "latitude",
                "longitude", "latlon", "altitude"
],
    MB     => [ "madname"
],
    MG     => [ "mgmname"
],
    MINFO  => [ "rmailbx", "emailbx"
],
    MR     => [ "newname"
],
    MX     => [ "preference", "exchange"
],
    NAPTR  => [ "order", "preference", "flags", "service", "regexp",
"replacement"  ],
    NIMLOC => [ "rdlength", "rdata"
],
    NS     => [ "nsdname"
],
    NSAP   => [ "idp", "dsp", "afi", "idi", "dfi", "aa"
],
    NULL   => [ "rdlength", "rdata"
],
    PTR    => [ "ptrdname"
],
    PX     => [ "preference", "map822", "mapx400"
],
    RP     => [ "mbox", "txtdname"
],
    RT     => [ "preference", "intermediate"
],
    SOA    => [ "mname", "rname", "serial", "refresh", "retry", "expire",
"minimum" ],
    SRV    => [ "priority", "weight", "port", "target"
],
    TEXT   => [ "txtdata"
],
    X25    => [ "psdn"
]
);


# returns a list of Resource Records of the asked for type
# for the given domain
# XXX seems to return (), but with an undefined element 0 !!!
#
# SOMETHING IS SCREWED UP
#   the mapping %typesbyname in DNS.pm assumes upper-case
#   ditto for %classesbyname
#
#   resolver->query does seem to return undef on error ???
sub  get_RR ($$)
{
    my ($dom, $rr) = @_;
    my ($resolver, $response, @hosts);

    $rr = uc($rr);  # NetDNS should be case-insensitive
    fatal "don't know about the '$rr' Resource Record type"
        unless (exists $RR_FIELDS{$rr});
    $resolver = new Net::DNS::Resolver;
    fatal "couldn't create a resolver"
        unless (defined($resolver) && $resolver);
    $response = $resolver->query($dom, $rr);
    # originally I was returning undef, on the assumption
    # that resolver was returning undef for a error
    # but () for no answer
    return ()
        unless (defined($response));
    @hosts = ();
#note 0, sprintf "'*** %d", scalar(@hosts);
    return @hosts
        unless ($response);
    for my $host ($response->answer) {
        #note 0, sprintf "== %d", scalar(@hosts);
        my %ans;
        for my $field (@{$RR_FIELDS{$rr}}) {
            $ans{$field} = $host->{$field};
        }
        #ddump "**>", \%ans;
        push @hosts, {%ans};
    }
    return @hosts;
}


# returns a list of hosts which will accept mail for
# that domain. My definition:
#   either is a domain with an MX record(s)
#     or   is a host name, has an A record
# an error only returns an empty list which can't
# be distinguished from no hosts.
sub  delivery_hosts ($)
{
    my ($dom) = @_;
    my (@recs);

    @recs = get_RR $dom, "MX";
    return ()
        unless (defined(@recs));
    return @recs
        if (scalar(@recs) > 0);
    @recs = get_RR $dom, "A";
    return ()
        unless (defined(@recs));
    return @recs;
    #    if (scalar(@recs) > 0);
}



Indexed By Date Previous: creation of lists
From: "Marites Constantino" <TEX@innotech.org>
Next: Subscribed user cant run who or which
From: Colin Forde <C.Forde@Queens-Belfast.AC.UK>
Indexed By Thread Previous: Re: Help finding which address...?
From: The Woodpecker <kevin@ols.net>
Next: dumb questions #47 & #48 :)
From: Jan Howard <janh@sonic.net>

Google
 
Search Internet Search www.greatcircle.com