1

I have a list of thousands of domains. For example:

.google.com
.gmail.com
.google.co
.yahoo.com

etc, etc, etc.

I need to resolve the IP addresses of these domains, and then, get the range whois. Example manual:

host -t a gmail.com = 216.58.192.69
whois 216.58.192.69 | grep CIDR = 216.58.192.0/19

But I could not work with lists. I put a mark error, in parenthesis

#!/bin/bash
cat domains.txt | host -t a (error) | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" > list.txt
cat list.txt | whois (error) | grep CIDR | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n > final.txt

Thanks a lot

Update... I think I got it, but it's not a very elegant script. There must be a better way. Additionally. First you have to delete from the list: points, comments, www, etc. (with sed)

dig +short -f domains.txt | egrep -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | uniq > ips
cat ips | while read ips; do whois $ips | grep CIDR; done | grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\/[0-9]\{1,\}' > cidr.txt
sort -o cidr.txt -u cidr.txt -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n cidr.txt

Important: The script need to check the list of IP/CIDR, to avoid (or delete) conflicts: Example:

54.200.0.0/14 is a subnetwork of 54.192.0.0/12

Additional request: Sometimes "whois" no response CIDR and its show the message:

% Types of queries are: POCs, ownerid, CIDR blocks, IP

How can I pass the ip consulted, to the final acl, if there is no CIDR ???

Thank you

1 Answers1

0
for X in `cat domains.txt`; 
do 
    host -t a  $X; 
done | awk 'BEGIN { FS = " " } ; { print $4 }' > ip.txt; 

for Y in `cat ip.txt`; 
do 
    whois $Y | grep CIDR; 
done
Hemang
  • 390
  • 3
  • 20
fipsbox
  • 126
  • 1
  • 3
  • Your script is better than mine. Thank you. However, CIDR creates conflicts (like mine). You must remember the question: "I have a list of thousands of domains". the script does not check the list of CIDR, to eliminate conflicts: Example: 54.200.0.0/14 is a subnetwork of 54.192.0.0/12 –  Dec 21 '15 at 20:57
  • Also, http://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-variable/27701642#27701642 – tripleee Dec 23 '15 at 05:22