File: mx

package info (click to toggle)
libnet-dns-perl 0.12-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 444 kB
  • ctags: 269
  • sloc: perl: 4,047; makefile: 59; sh: 17
file content (45 lines) | stat: -rwxr-xr-x 766 bytes parent folder | download | duplicates (2)
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
44
45
#!/usr/local/bin/perl -w
# $Id: mx,v 1.6 1997/10/02 05:00:51 mfuhr Exp $

=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 <mfuhr@dimensional.com>

=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 = new Net::DNS::Resolver;
my @mx = mx($res, $dname);

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