0

How to do DNS lookup of an IP range using shell script

when I do dig -x and provide an ip i get reverser DNS for the respective ip. However if I give range either CIDRs or ip range from & to thats a long manual process, which I want to get it working using shell script.

I tried

dig -x 1x.xx.xx.xx

;; ANSWER SECTION:

1x.xx.xx.xx.foo.addr. port IN   PTR

I want to see reverse DNS of all ips falling in that range when I pass either 1x.xx.xx.xx/24 or 1x.xx.xx.xx - 1x.xx.xx.xxx

  • Sorry, but S.O. isn't a free coding service. You're expected to research the problem, post your best attempt at solving the problem, including sample inputs and expected outputs. Please read [Help How-to-ask](https://stackoverflow.com/Help/How-to-ask) before posting more Qs here. One hint, do you know about `grep` or `awk` ? maybe `dig -x ... | grep 'stuff you want to find'` can get you started. Good luck. – shellter May 30 '19 at 13:37
  • Yeah I got it, I was just expecting any way which could be give me an output of CIDR range. I understood when you say about grep or awk but the question was instead of looking for 1 ip each time, can I get output for all ips falling in the CIDR range? I got the way to do it by using nmap ```nmap -sL 4x.xx.xx.0/24 | awk '/Nmap scan report/{print $NF}' | xargs -I % bash -c 'echo "%: $(dig -x % +short)"'``` – SunilGhargaonkar May 31 '19 at 13:21

1 Answers1

1

I got the way to do this. using nmap we can achieve this.

nmap -sL 4x.xx.xx.0/24 | awk '/Nmap scan report/{print $NF}' | xargs -I % bash -c 'echo "%: $(dig -x % +short)"'

output

41.74.205.0:
4x.xx.xx.1:a2b-foo.c.
4x.xx.xx.2:a2b-foo.c.
4x.xx.xx.3:
4x.xx.xx.4:
4x.xx.xx.5:
4x.xx.xx.6:
41.74.205.7:foo-smtp-delivery-foo.com.
41.74.205.8:foo-smtp-delivery-foo.com.
41.74.205.9:foo-smtp-delivery-foo.com.
41.74.205.10:foo-smtp-delivery-foo.com.

I was expecting this way. I can now create a shell script and ask for an input range and show this sort of output.