File: mx

package info (click to toggle)
libnet-dns-perl 0.63-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 836 kB
  • ctags: 425
  • sloc: perl: 6,796; sh: 109; ansic: 104; makefile: 59
file content (43 lines) | stat: -rwxr-xr-x 752 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/local/bin/perl -w
# $Id: mx 264 2005-04-06 09:16:15Z olaf $

=head1 NAME

mx - Print a domain's MX records

=head1 SYNOPSIS

C<mx> I<domain>

=head1 DESCRIPTION

C<mx> prints a domain's MX records, sorted by preference.

=head1 AUTHOR

Michael Fuhr <mike@fuhr.org>

=head1 SEE ALSO

L<perl(1)>, L<axfr>, L<check_soa>, L<check_zone>, L<mresolv>, L<perldig>,
L<Net::DNS>

=cut

use strict;
use File::Basename;
use Net::DNS;

die "Usage: ", basename($0), " domain\n" unless (@ARGV == 1);

my $dname = $ARGV[0];
my $res   = Net::DNS::Resolver->new;
my @mx    = mx($res, $dname);

if (@mx) {
	foreach my $rr (@mx) {
		print $rr->preference, "\t", $rr->exchange, "\n";
	}
} else {
	print "Can't find MX hosts for $dname: ", $res->errorstring, "\n";
}