perl script for generating nsap-to-name mappings under NSAP.INT.

colella@nist.gov Fri, 14 October 1994 16:10 UTC

Received: from ietf.nri.reston.va.us by IETF.CNRI.Reston.VA.US id aa04614; 14 Oct 94 12:10 EDT
Received: from CNRI.Reston.VA.US by IETF.CNRI.Reston.VA.US id aa04610; 14 Oct 94 12:10 EDT
Received: from mailhost.lanl.gov by CNRI.Reston.VA.US id aa09685; 14 Oct 94 12:10 EDT
Received: from noc-gw.lanl.gov by mailhost.lanl.gov (8.6.8.1/1.2) id KAA10757; Fri, 14 Oct 1994 10:09:41 -0600
Received: by noc-gw.lanl.gov (8.6.9/SMI-4.1) id KAA02284; Fri, 14 Oct 1994 10:09:20 -0600
Received: from mailhost.lanl.gov by noc-gw.lanl.gov (8.6.9/SMI-4.1) id KAA02281; Fri, 14 Oct 1994 10:09:19 -0600
Received: from merit.edu by mailhost.lanl.gov (8.6.8.1/1.2) id KAA10569; Fri, 14 Oct 1994 10:09:20 -0600
Received: from osi.ncsl.nist.gov (OSI.NCSL.NIST.GOV [129.6.48.100]) by merit.edu (8.6.8.1/merit-1.0) with SMTP id LAA00116; Fri, 14 Oct 1994 11:36:38 -0400
Received: from emu.ncsl.nist.gov.noname by osi.ncsl.nist.gov (4.1/SMI-4.0-MHS-7.0) id AA11092; Fri, 14 Oct 94 11:37:03 EDT
Date: Fri, 14 Oct 1994 11:37:03 -0400
Message-Id: <9410141537.AA11092@osi.ncsl.nist.gov>
To: clns@uni-muenster.de, wg-llt-clns@rare.nl, noop@merit.edu, tuba@merit.edu
Subject: perl script for generating nsap-to-name mappings under NSAP.INT.
Cc: colella@nist.gov
Sender: ietf-archive-request@IETF.CNRI.Reston.VA.US
From: colella@nist.gov

(apologies for multiple copies....)

For those who have NSAPs in the DNS, want to put in the reverse
mapping, but can't stand the thought of doing the editing.....
attached is a perl script that does it for you.  Point it to
the domain that has the NSAPs in it, give it your prefix, and
it generates the zone file for the reverse lookup (well, not
including the SOA and NS records).

--Richard


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

#!/usr/local/bin/perl
#
# Build the reverse nsap lookup info for DNS
# -------------------------------------------
#
# send comments about this program to colella@nist.gov

#############################################################
$HELP = <<EOF;
Usage: $0 [-d[ebug]] <nsap_prefix> <domain_name>

    <nsap_prefix>  hex nsap prefix that gets combined with
                     NSAP.INT for your reverse lookup root.
    <domain_name>  DNS name in which to look for NSAP RRs.

Synopsis:
	Read NSAPs from the DNS and build DNS reverse nsap lookup
	info (i.e., nsap-to-name tree).  The output is stored
	in file <domain_name>.rev.

	To register a reverse nsap tree under the nsap.int domain
	(see RFC 1637), send email to nsap@ripe.net.

Example:
    % $0  47.0005.80  nsap.nist.gov
             (output stored in nsap.nist.gov.rev)
EOF
#############################################################


$_ = $ARGV[0];
if (/-d/) {
	$DEBUG = 1;
	shift;
}
if (/-h/) {
	print $HELP;
	exit 1;
}
$pre = $ARGV[0];
shift;
$domain = $ARGV[0];
unless ($pre && $domain) {
	print $HELP;
	exit 1;
}

$domain =~ tr/A-Z/a-z/;		# translate to lower case
$pre =~ tr/A-Z/a-z/;
$pre =~ s/\.//g;			# pitch "."s

###
###  output file name based on domain name
###
$zone = "./$domain.rev";
if (-e "$zone") {
	print STDERR "file $zone exists, overwrite ([y] | n)? ";
	$ans = <STDIN>; chop ($ans);
	if ( ($ans ne "")  &&  ($ans !~ /^[yY]+/) ) {
		print "exiting...\n";
		exit;
	}
}
open (REV, "> $zone") || die "Can't open $zone";

###
###  generate $ORIGIN
###
$tmp = $pre;
reverse ($tmp);
while ( $tmp ne "" ) {
	$rev_name .= ( chop($tmp) . ".");
}
print REV "\$ORIGIN\t\t$rev_name","nsap.int.\n;\n";

###
###  get nameserver for domain
###
$nameserver = $1 if `nslookup -query=ns $domain` =~ /nameserver = (.*)/;
print STDERR "nameserver for $domain is $nameserver\n" if $DEBUG;

if ($nameserver eq "") {
	close (REV);
	unlink ($rev_name);
	die "Can't get nameserver\n";
}

###
###  now get list of nsap entries to tmp-file
###  close STDOUT to avoid extraneous nslookup output
###
close (STDOUT);
$TMP="/tmp/build_rev_nsap.$$";
open (NSL,"|-") || exec 'nslookup','-',$nameserver;
print NSL "ls -t nsap $domain > $TMP\n";
close (NSL);


unless (open(IN,$TMP)) {
	close (REV);
	unlink ($rev_name);
	die "Can't open $TMP\n";
}
while (<IN>) {
	print STDERR "\n$_" if $DEBUG;
	next if /ls -t nsap/;
	($dummy,$host,$nsap) = split;
	next unless $host;
	$host =~ tr/A-Z/a-z/;
	$host = "$host.$domain";
	###
	### strip "."s from nsap and make lc
	### if prefix matches,
	###		- delete prefix from nsap
	###		- generate the reverse name RR
	###
	$nsap =~ s/\.//g;
	$nsap =~ tr/A-Z/a-z/;
	if ( $i=index($nsap, $pre) == 0 ) {
		substr ($nsap, 0, length($pre)) = "";
		$rev_nsap = "";
		while ($nsap ne "") {
			$rev_nsap .= ( chop($nsap) . "." );
		}
		chop ($rev_nsap);				# drop trailing "."
		print REV "$rev_nsap\tIN\tPTR\t$host.\n";
	}


	print STDERR "host=$host\tnsap=$nsap\n" if $DEBUG;
}
close(IN);
close(REV);
unlink $TMP;
chmod (0664,$zone);
exit 0;