nmap -R -sL | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('

List of reverse DNS records for a subnet

This command uses nmap to perform reverse DNS lookups on a subnet. It produces a list of IP addresses with the corresponding PTR record for a given subnet. You can enter the subnet in CDIR notation (i.e. /24 for a Class C)). You could add "--dns-servers x.x.x.x" after the "-sL" if you need the lookups to be performed on a specific DNS server. On some installations nmap needs sudo I believe. Also I hope awk is standard on most distros.
Sample Output
( is ww-in-f96.google.com
( is ww-in-f97.google.com
( is ww-in-f98.google.com
( is ww-in-f99.google.com
( is ww-in-f100.google.com
( is ww-in-f101.google.com
( is ww-in-f102.google.com
( is ww-in-f103.google.com
( is ww-in-f104.google.com
( is ww-in-f105.google.com
( is ww-in-f106.google.com
( no PTR
( no PTR
( no PTR
( no PTR
( no PTR
( is ww-in-f112.google.com
( is ww-in-f113.google.com
( no PTR
( is ww-in-f115.google.com
( is ww-in-f116.google.com
( no PTR
( is ww-in-f118.google.com
( no PTR
( is ww-in-f120.google.com
( no PTR
( no PTR
( is ww-in-f123.google.com
( no PTR
( is ww-in-f125.google.com
( is ww-in-f126.google.com
( is ww-in-f127.google.com

By: netsaint
2009-09-02 16:33:15

These Might Interest You

What Others Think

Looks like different version of nmap spit out different text. Just do the nmap -R -sL network and you see what comes out. Very quick and simple. The format the output the way you need...
netsaint · 424 weeks ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: