This snippet is designed to take a textfile of domain names, one per line as the first command line arg and a nameserver as the second - it then performs a mx lookup on the domain, it then does a lookup on the mx domain returned and does a reverse lookup of the ip address.
Its designed to help administrators maintain nameservers and or mailservers that host lots of domains, identifying dead domains and or domains which your servers may think they are authoratitive for which they are not.
Uses Net::DNS#!/usr/bin/perl use strict; use Net::DNS; my $domains = $ARGV[0]; my $nameserver = $ARGV[1]; open(DOMAINS, "< $domains") or die "can't open $domains: $ +!"; while(<DOMAINS>){ my $domain = chomp($_); my $domain = $_; print "-------------------------------------\n"; print "Checking domain: $domain\n"; my $res = new Net::DNS::Resolver; $res->nameservers("$nameserver"); my @mx = mx($res, $domain); if (@mx) { foreach my $rr (@mx) { my $ip = &lookup($rr->exchange,); print $rr->preference, " ", $rr->exchange, " - +> $ip\n"; } } else { print "can't find MX records for $domain: ", $res->err +orstring, "\n"; } } close(DOMAINS) or die "can't close $domains: $!"; sub lookup { my $domain = $_[0]; my $res = new Net::DNS::Resolver; my $query = $res->search($domain); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "A"; my $rev = &rev_lookup($rr->address,); my $address = $rr->address,; my $lookedup = "$address -> $rev"; return $lookedup; } } else { return $res->errorstring,; } } sub rev_lookup { my $ip = $_[0]; my $res = new Net::DNS::Resolver; my $query = $res->search($ip); if ($query) { foreach my $rr ($query->answer) { next unless $rr->type eq "PTR"; return $rr->rdatastr,; } } else { return $res->errorstring,; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DNS MX checking
by blakem (Monsignor) on Aug 14, 2002 at 08:46 UTC | |
by htaccess (Initiate) on Aug 15, 2002 at 09:55 UTC |