Skip to content

Instantly share code, notes, and snippets.

@MACscr
Last active September 4, 2019 00:04
Show Gist options
  • Save MACscr/5c7a3b9836be5746bf065724e1e42c1c to your computer and use it in GitHub Desktop.
Save MACscr/5c7a3b9836be5746bf065724e1e42c1c to your computer and use it in GitHub Desktop.
loop through cpanel server domains and check if they resolve # and if their first nameserver matches one of our nameserver ip's
#!/bin/bash
# loop through server domains and check if they resolve
# and if their first nameserver matches one of our nameserver ip's
in_array() {
needle="$1"
shift
haystack=("$@")
for i in "${haystack[@]}"; do
if [[ "$i" == "$needle" ]]; then
echo 1
return
fi
done
echo 0
return
}
# our nameserver ip's
possible_ips=('67.225.159.27' '155.138.228.129' '108.61.220.172' '104.238.173.9' '104.238.149.200')
echo "domain,owner,ipaddress,nameserver,nameserver_ip,reason"
while IFS=': ' read domain owner
do
nameserver=`dig +short NS "$domain" | head -n 1`
# if $nameserver is empty
if [ -z "$nameserver" ];then
echo "$domain","$owner","na","na","na","no nameservers"
continue
fi
nameserver_ip=`dig +short "$nameserver" | head -n 1`
# if nameserver has no ip address
if [ -z "$nameserver_ip" ];then
echo "$domain","$owner","na","$nameserver","na","nameserver does not resolve"
continue
fi
# not one of our nameservers
ip_address=`dig +short "$domain" | head -n 1`
nameserver_check=`in_array "$nameserver_ip" "${possible_ips[@]}"`
if [ "$nameserver_check" -eq "0" ];then
echo "$domain","$owner","$ip_address","$nameserver","$nameserver_ip","not our nameserver"
continue
fi
echo "$domain","$owner","$ip_address","$nameserver","$nameserver_ip","status good"
done < /etc/trueuserdomains
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment