File: perldig

package info (click to toggle)
libnet-dns-perl 0.59-1etch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 828 kB
  • ctags: 400
  • sloc: perl: 6,650; sh: 220; ansic: 101; makefile: 60
file content (70 lines) | stat: -rwxr-xr-x 1,263 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/local/bin/perl -w
# $Id: perldig 264 2005-04-06 09:16:15Z olaf $

=head1 NAME

perldig - Perl script to perform DNS queries

=head1 SYNOPSIS

C<perldig> [ C<@>I<nameserver> ] I<name> [ I<type> [ I<class> ] ]

=head1 DESCRIPTION

Performs a DNS query on the given name.  The record type
and class can also be specified; if left blank they default
to A and IN.

=head1 AUTHOR

Michael Fuhr <mike@fuhr.org>

=head1 SEE ALSO

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

=cut

use strict;

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

my $res = Net::DNS::Resolver->new;

if (@ARGV && ($ARGV[0] =~ /^@/)) {
	my $nameserver = shift;
	$nameserver =~ s/^@//;
	$res->nameservers($nameserver);
}

die "Usage: ", basename($0), " [ \@nameserver ] name [ type [ class ] ]\n"
	unless (@ARGV >= 1) && (@ARGV <= 3);

my ($name, $type, $class) = @ARGV;
$type  ||= "A";
$class ||= "IN";

if (uc($type) eq "AXFR") {
	
	my @rrs = $res->axfr($name, $class);
	
	if (@rrs) {
		foreach my $rr (@rrs) {
			$rr->print;
		}		
	} else {
		die "zone transfer failed: ", $res->errorstring, "\n";
	}
	
} else {

	my $answer = $res->send($name, $type, $class);
	
	if ($answer) {
		$answer->print;
	} else {
		die "query failed: ", $res->errorstring, "\n";
	}
}