Use dig
:
for host in hostA.com hostB.com hostC.com
do
# get ips to host using dig
ips=($(dig "$host" a +short | grep '^[.0-9]*$'))
for ip in "${ips[@]}";
do
printf 'allow\t\t%s\n' "$ip"
done
done > allowedip.inc
Saída:
$ cat allowedip.inc
allow 64.22.213.2
allow 67.225.218.50
allow 66.45.246.141
Faz um loop por meio de um arquivo com um host por linha:
while IFS= read -r host;
do
# get ips to host using dig
ips=($(dig "$host" a +short | grep '^[.0-9]*$'))
for ip in "${ips[@]}";
do
printf 'allow\t\t%s\n' "$ip"
done
done < many_hosts_file > allowedip.inc