Subversion Repositories sysadmin_scripts

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
80 rodolico 1
#! /usr/bin/env perl
2
 
3
use strict;
4
use warnings;
5
 
82 rodolico 6
use Getopt::Long;
7
 
81 rodolico 8
# this is a filter. A list of domains is passed on STDIN
9
# for each domain, it will check that the DNS record matches
10
# $myIP and, if it does not, will display the domain on 
11
# STDOUT.
12
 
13
# Strongly recommend you verify before deleting any web sites, however.
14
 
15
# A sample call is
80 rodolico 16
# ls /var/www/ | grep '^.*\..*$' | grep -v '^quota' | ./doWeHost.pl
81 rodolico 17
# this gets all domains listed in /var/www which contain at least one
18
# period. Since the quota controls for ISPConfig are in here and have
19
# a period in their filenames, we use grep -v to exclude them
20
# that list is then piped to the script on STDIN
80 rodolico 21
 
82 rodolico 22
# getMyIP
23
# this finds the first IP address, assuming ifconfig is installed
24
# and a valid IP is of the form
25
# inet 192.168.1.32  netmask 255.255.255.0  broadcast 10.111.111.255
26
sub getMyIP {
27
  my @ip = grep{ /^\s*inet [\d.]+.*broadcast/ } `ifconfig -a`;
28
  if ( $ip[0] =~ m/^\s*inet\s+([\d.]+)/ ) { 
29
     return $1;
30
   }
31
}
32
 
33
# the IP address to check against 
34
my $ip = &getMyIP();
35
# the record type to check. Blank checks A and CNAME
36
my $recordType = '';  # defaults to A record
37
# the dns server to use for lookups
80 rodolico 38
my $dnsServer = '9.9.9.9';
39
 
82 rodolico 40
# Check for CLI options
41
# -r or --recordtype determines type of record to find
42
# -i or --ip is our local IP
43
# -d or --dns is the remote DNS server to use
44
GetOptions( 
45
      "recordtype:s" => \$recordType,
46
      "ip:s" => \$ip,
47
      'dns:s' => \$dnsServer
48
      );
49
 
50
# go through all domains on STDIN      
80 rodolico 51
while ( my $domain = <> ) {
82 rodolico 52
   #Remove any trailing spaces
80 rodolico 53
   chomp $domain;
82 rodolico 54
   # run dig against it
55
   my $result = `dig +short \@$dnsServer $domain $recordType`;
56
   # check if it matches our ip and, if not print to STDOUT
57
   print "$domain\n" unless $result =~ m/$ip/;
80 rodolico 58
}