#!/usr/bin/perl

# Quick and dirty NAPTR lookup
# Usage: naptr.pl phone-number

# For CNET use, include the country code, and do not use
# spaces, dashes, or punctuation.

use Net::DNS;
use strict;

# Address of DNS resolver to use.
my $resolverIP = '76.164.8.68';

# Grab the phone number from the command line and reverse it.
my $lookup = scalar reverse $ARGV[0];

# Change each digit to that digit plus a dot.
$lookup =~ s/(\d)/$1./g;

# Append std.ckts.info to the lookup name.
# Thus, 14427877 becomes 7.7.8.7.2.4.4.1.std.ckts.info
$lookup .= 'std.ckts.info';

# Create a resolver object to make the query.
my $res = Net::DNS::Resolver->new;
$res->nameservers($resolverIP);
my $query = $res->search($lookup,'NAPTR');
if($query) {
	foreach my $rr ($query->answer) {
		print "Found:\n";
		print $rr->rdatastr . "\n";
	}
} else {
	print "No record found.\n";
}

exit 0;
