I need to resolve all "A" records for a domain to ip addresses if they exist while creating a bash script.
I've looked to see if there was a dig command to retrieve all a records for a domain but could not find any, so I am using the hostnames that I know exist from a visual that is given to us by a particular online chat program.
This is what I have so far
#!/bin/bash
pricks=(
"c1.domain.com"
"c2.domain.com"
"c3.domain.com"
"c4.domain.com"
"c5.domain.com"
"c6.domain.com"
"c7.domain.com"
"c8.domain.com"
"c9.domain.com"
"c10.domain.com"
"c11.domain.com"
"c12.domain.com"
"c13.domain.com"
"c14.domain.com"
"c15.domain.com"
"c16.domain.com"
"c17.domain.com"
"c18.domain.com"
"c19.domain.com"
"c20.domain.com"
)
for prick in "${pricks[@]}"
do
echo "apf -d $prick \"$prick\"" >> add_apf_rules.sh
done
exit
This gives me the following output which I can easily execute and which will add the hostnames to the apf deny hosts file ...
apf -d c1.domain.com "c1.domain.com"
apf -d c2.domain.com "c2.domain.com"
apf -d c3.domain.com "c3.domain.com"
apf -d c4.domain.com "c4.domain.com"
apf -d c5.domain.com "c5.domain.com"
apf -d c6.domain.com "c6.domain.com"
apf -d c7.domain.com "c7.domain.com"
apf -d c8.domain.com "c8.domain.com"
apf -d c9.domain.com "c9.domain.com"
apf -d c10.domain.com "c10.domain.com"
apf -d c11.domain.com "c11.domain.com"
apf -d c12.domain.com "c12.domain.com"
apf -d c13.domain.com "c13.domain.com"
apf -d c14.domain.com "c14.domain.com"
apf -d c15.domain.com "c15.domain.com"
apf -d c16.domain.com "c16.domain.com"
apf -d c17.domain.com "c17.domain.com"
apf -d c18.domain.com "c18.domain.com"
apf -d c19.domain.com "c19.domain.com"
apf -d c20.domain.com "c20.domain.com"
Hostnames are not allowed in the "/etc/apf/deny_hosts.rules" so I need a way to resolve the hostname to an ip, if it exists, and place the ip instead of the hostname.
How can I use getent to accomplish my task?
getent hosts c15.domain.com | awk '{ print $1 }'