Subversion Repositories sysadmin_scripts

Rev

Rev 81 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 81 Rev 82
Line 1... Line 1...
1
#! /usr/bin/env perl
1
#! /usr/bin/env perl
2
 
2
 
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
 
5
 
-
 
6
use Getopt::Long;
-
 
7
 
6
# this is a filter. A list of domains is passed on STDIN
8
# this is a filter. A list of domains is passed on STDIN
7
# for each domain, it will check that the DNS record matches
9
# for each domain, it will check that the DNS record matches
8
# $myIP and, if it does not, will display the domain on 
10
# $myIP and, if it does not, will display the domain on 
9
# STDOUT.
11
# STDOUT.
10
 
12
 
Line 15... Line 17...
15
# this gets all domains listed in /var/www which contain at least one
17
# this gets all domains listed in /var/www which contain at least one
16
# period. Since the quota controls for ISPConfig are in here and have
18
# period. Since the quota controls for ISPConfig are in here and have
17
# a period in their filenames, we use grep -v to exclude them
19
# a period in their filenames, we use grep -v to exclude them
18
# that list is then piped to the script on STDIN
20
# that list is then piped to the script on STDIN
19
 
21
 
-
 
22
# getMyIP
20
# the IP address of the web hosting machine (ie, this machine)
23
# this finds the first IP address, assuming ifconfig is installed
21
my $myIP = '74.113.60.152';
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
 
22
# the IP address of a remote DNS server
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
23
my $dnsServer = '9.9.9.9';
38
my $dnsServer = '9.9.9.9';
24
 
39
 
-
 
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      
25
while ( my $domain = <> ) {
51
while ( my $domain = <> ) {
-
 
52
   #Remove any trailing spaces
26
   chomp $domain;
53
   chomp $domain;
-
 
54
   # run dig against it
27
   my $result = `dig +short \@$dnsServer $domain`;
55
   my $result = `dig +short \@$dnsServer $domain $recordType`;
-
 
56
   # check if it matches our ip and, if not print to STDOUT
28
   print "$domain\n" unless $result =~ m/$myIP/;
57
   print "$domain\n" unless $result =~ m/$ip/;
29
}
58
}