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