Dreft

Dreft is a quick and dirty tool that I wrote some time ago to do a bunch of reverse DNS lookups for a CIDR block. Its a pretty simple script, the most interesting part is the ugly workaround to create an in-addr.arpa address from a Net::IP object, somehow I couldn’t convince Net::IP to do this for me when iterating addresses. Usage is pretty straightforward too:<

hessch@blokje:~$ dreft 4.2.2.0/29    
4.2.2.1 -> vnsc-pri.sys.gtei.net.
4.2.2.2 -> vnsc-bak.sys.gtei.net.
4.2.2.3 -> vnsc-lc.sys.gtei.net.
4.2.2.4 -> vnsc-pri-dsl.genuity.net.
4.2.2.5 -> vnsc-bak-dsl.genuity.net.
4.2.2.6 -> vnsc-lc-dsl.genuity.net.

Below you’ll find the complete script:

dreft.pl link
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
#!/usr/bin/perl -w

# dreft - reverse dns enumerator
# Hessel Schut, hessel@isquared.nl, 2008-06-24

use strict;

use Net::DNS;
use Net::IP;

my $ip = new Net::IP ($ARGV[0])  or die (Net::IP::Error());
my $res = Net::DNS::Resolver->new;

do {
        # $ip->reverse_ip doesn't work when iterating IP addresses
        # horrible kludge to in-addr.arpafy the current IP:
        my $ptr = join('.', reverse(split /\./, $ip->ip()));
        $ptr .= ".in-addr.arpa";

        my $rr = $res->query($ptr, qw(PTR));

        if ($rr) {
                print $ip->ip()." -> ".(($rr->answer)[0]->rdatastr)."\n";
        };
} while (++$ip);

Comments