Automatic DNS check of apache virtualhosts

#!/usr/bin/perl

$space=65;
$myip="212.242.77.75";      # Domains with this ip gets "working" stamp
open(fh, "/usr/local/apache2/conf/httpd.conf");
while ($dat=<fh>)
{
        if ($dat=~ /servername/i)
        {
                $dat =~ s/ //g;chop($dat);
                if ( lc ( substr($dat,0,10)) eq "servername")
                {
                        $domain=substr($dat,10,length($dat));
                        print $domain;
                        $res = `host -t a $domain`;

                        $i=length($domain); while ($i<40) {print " "; $i++;}

                        @ip=split(" ",$res);

                        if ($res =~ /NXDOMAIN/)                 {print "Not working(No A)";}
                        elsif ($res =~ /SERVFAIL/)              {print "Not working(No NS)";}
                        elsif ($res =~ /is an alias/)           {
                                                                        if (@ip[9] eq $myip) { print "Working";}
                                                                        else { print "CNAME ".@ip[5]."=>".@ip[9]; }
                                                                }
                        elsif ($res =~ /has address/)           {
                                                                        if (@ip[3] eq $myip) { print "Working"; }
                                                                        else { print @ip[3];}
                                                                }
                        else {print "Not working";}
                        print "\n";
                }
        }
}
close(fh);

 

Dette indlæg blev udgivet i Apache, Knowledge Base, Networking, Old Base. Bogmærk permalinket.

Skriv et svar