Tag Archives: nameservers

How to find which Apache domains have alien NS servers

Here is a script that helps you find which domains configured with Apache have NS es located on different servers.

# Bash script to tell which vhosts configured with Apache have alien
# NS servers.
# Written by Badan Sergiu, https://badan.wordpress.com/


# Create temporary directory if it doesn't exist
if [ ! -d $tmpdir ]; then
   mkdir $tmpdir

# Create a list of IP addresses on the server
ifconfig | grep inet | awk '{print $2}' | cut -d: -f2 | sort \
   | uniq > $tmpdir/iplist

# Dump all configured vhosts;
$httpd -S 2>&1 | grep namevhost | awk '{print $4}' > $tmpdir/allvhosts.txt

# select 2nd level domain
for domain in $(cat $tmpdir/allvhosts.txt); do
   echo $domain | awk -F. '{print $(NF-1) "." $NF}'
done \
   | sort | uniq > $tmpdir/2domains.txt

# find which 2nd level domain has alien IP
for domain2 in $(cat $tmpdir/2domains.txt); do
   for nameserver in $(dig ns $domain2 +short); do
      nsip=$(dig a $nameserver +short | head -n 1)
      if [ -z $(grep $nsip $tmpdir/iplist) ]; then
         echo "alien $nameserver ($nsip) for $domain2"
done > $tmpdir/report.txt

# print the report
case $1 in
      cat $tmpdir/report.txt
      echo "Following domains have alien NS servers (use -v for verbose):"
      cat $tmpdir/report.txt | awk '{print $5}' | sort | uniq
%d blogeri au apreciat asta: