5 =head1 NAME $RCSfile: checkdns,v $
7 Check DNS by attempting to call gethostbyname of a well known host.
15 Andrew DeFaria <Andrew@ClearSCM.com>
23 Wed Aug 30 21:03:14 CDT 2006
27 $Date: 2011/04/15 15:05:16 $
33 Usage: checkdns [-u|sage] [-v|erbose] [-d|ebug]
34 [-s|leep <n>] [-l|ogpath <path>]
37 -u|sage Print this usage
38 -v|erbose: Verbose mode
39 -de|bug: Emit debug information
41 -h|ost: Host to check (Default: google.com)
42 -s|leep <n>: Set sleep period to <n> minutes (Default: 15 minutes)
43 -l|ogpath <path>: Put the log file in <path> (Default: /var/log)
44 -da|emon: Whether to go into daemon most (Default: yes)
48 This script will look at the security logfile for attempted breakins and then
49 use whois to report them to the upstream provider.
60 use lib "$FindBin::Bin/../lib";
66 my $VERSION = '$Revision: 1.6 $';
67 ($VERSION) = ($VERSION =~ /\$Revision: (.*) /);
69 $0 = $FindBin::Script;
71 my ($log, $initial_sleep);
76 logpath => '/var/local/log',
77 usage => sub { Usage },
78 verbose => sub { set_verbose },
79 debug => sub { set_debug },
88 my @ipaddrs = gethostbyname $host;
91 debug "Host: $host (ipaddrs empty)";
93 # Cut down sleep time to monitor this outage more closely but do not go
94 # below once a minute.
95 if ($opts{sleep} > 1) {
96 $opts{sleep} -= $opts{sleep} / 2;
104 # Successful lookup - set $sleep to $initial_sleep
105 $opts{sleep} = $initial_sleep;
113 my $errors = $log->errors;
115 $log->msg("$errors errors encountered since starting") if $errors;
116 $log->msg('Caught interrupt - shutting down');
131 ) or Usage 'Invalid parameter';
133 $initial_sleep = $opts{sleep};
136 $SIG {TERM} = \&Shutdown;
138 # Call sethostent so that gethostbyname is fresh everytime
142 path => $opts{logpath},
143 timestamped => 'yes',
148 "Started $FindBin::Script $VERSION logging to $opts{logpath}/$FindBin::Script.log"
151 if ($opts{sleep} > 1) {
152 $log->msg ("Polling DNS on host $opts{host} every $opts{sleep} minutes");
154 $log->msg ("Polling DNS on host $opts{host} every minute");
157 $opts{daemon} = 0 if get_debug;
159 EnterDaemonMode if $opts{daemon};
162 my $status = CheckDNS $opts{host};
165 $log->err ("Unable to resolve IP address for $opts{host}");
167 $log->msg ("Successfully resolved $opts{host}");
170 sleep $opts{sleep} * 60;
175 =head1 CONFIGURATION AND ENVIRONMENT
177 DEBUG: If set then $debug is set to this level.
179 VERBOSE: If set then $verbose is set to this level.
181 TRACE: If set then $trace is set to this level.
189 L<Getopt::Long|Getopt::Long>
191 =head2 ClearSCM Perl Modules
204 <a href="http://clearscm.com/php/scm_man.php?file=lib/Display.pm">Display</a><br>
205 <a href="http://clearscm.com/php/scm_man.php?file=lib/Logger.pm">Logger</a><br>
206 <a href="http://clearscm.com/php/scm_man.php?file=lib/Utils.pm">Utils</a><br>
211 =head1 BUGS AND LIMITATIONS
213 There are no known bugs in this script
215 Please report problems to Andrew DeFaria <Andrew@ClearSCM.com>.
217 =head1 LICENSE AND COPYRIGHT
219 Copyright (c) 2004, ClearSCM, Inc. All rights reserved.