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.

#!/bin/bash
# Bash script to tell which vhosts configured with Apache have alien
# NS servers.
# Written by Badan Sergiu, https://badan.wordpress.com/
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

tmpdir=/tmp/alienns
httpd=/usr/sbin/httpd

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

# 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"
      fi
   done
done > $tmpdir/report.txt

# print the report
case $1 in
   -v)
      cat $tmpdir/report.txt
   ;;
   *)
      echo "Following domains have alien NS servers (use -v for verbose):"
      cat $tmpdir/report.txt | awk '{print $5}' | sort | uniq
esac
Anunțuri

Lasă un răspuns

Completează mai jos detaliile tale sau dă clic pe un icon pentru a te autentifica:

Logo WordPress.com

Comentezi folosind contul tău WordPress.com. Dezautentificare / Schimbă )

Poză Twitter

Comentezi folosind contul tău Twitter. Dezautentificare / Schimbă )

Fotografie Facebook

Comentezi folosind contul tău Facebook. Dezautentificare / Schimbă )

Fotografie Google+

Comentezi folosind contul tău Google+. Dezautentificare / Schimbă )

Conectare la %s

%d blogeri au apreciat asta: