0

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 }'
Curious Sam
  • 317
  • 2
  • 5
  • 15
  • Please clarify your problem: is it about querying all A records from zone domain.com or resolving a (known) list of domain names? – WhiteWind Feb 21 '18 at 06:52
  • I was not able to find a command to query all A records so I was showing what I have come up with. I am very open to suggestions and whatever way works best is what I will use. I am not sure I am on the right track but I know for sure I am not too far off. – Curious Sam Feb 21 '18 at 08:38

1 Answers1

0

You can try to use host -l domain.com or dig domain.com AXFR (they both do the same thing) but it's very likely forbidden by owner of DNS server for security reasons.

If it is, then there is no way to retrieve all A records.

EDIT: I can not understand what are you asking for, so I start guessing:

Q: How can I alter my first script in order to get result:

apf -d 66.96.162.92 "c1.domain.com"
apf -d 66.96.162.93 "c2.domain.com"
apf -d 66.96.162.94 "c3.domain.com"

A:

for prick in "${pricks[@]}"; do
   echo apf -d $(getent hosts "$prick") >> add_apf_rules.sh
done
WhiteWind
  • 251
  • 1
  • 3