#!/usr/bin/perl # # File: modemcheck.pl # Description: Tests for Internet connectivity through standard cable # modem; uses X10 to reset modem in the event of failure # # Author: Ozymandias # Email: Ozymandias29@hotmail.com # Version: .3 # Copyright ©: 2000 Matt Beland. All rights reserved. # License: This script is redistributable under the terms of the GPL. # # Dependencies: Heyu X10 Control software, CM11A X10 two-way controller, X10 # module for modem # # Heyu can be obtained from http://www.prado.com/~dbs/ # This script was written using version 1.28h # # Variables: # # $admin_email: Email address notifications should go to # $error_email: Errorlog email; used as "From: in notifications # $device: Heyu address of cable modem; e.g., a5 or modem # $target: IP address of test target; I recommend the network gateway # (of your cable service, of course.) # # # User-defined variables - THESE MUST BE CHANGED FOR THE SCRIPT TO WORK $admin_email = "you@/didntchangeit.com"; $error_email = "did@/you.com"; $device = "a1"; $target = "192.168.1.1"; # define commands needed $ping ="/bin/ping -c 1 "; # Ping $kill_modem = "/usr/local/bin/heyu turn $device off"; # Kill modem $start_modem = "/usr/local/bin/heyu turn $device on"; # Start modem # begin test $linecount = 0; $errortime = localtime; open (I,"$ping $target |"); # Is it down? while() { chop $_; $linecount = $linecount + 1; if($linecount == 2) { if(/unreachable/i) { # Connection down $errortime = localtime; $wait = time; # Test again in 5 minutes $wait = $wait + 300; until($go >= $wait) { $go = time; }; open (II,"$ping $target |"); while() { chop $_; if(/Unreachable/) { $error = 2; $errortime = localtime; system "$kill_modem"; $wait = time; $wait = $wait + 60; until($go >= $wait) { $go = time; }; system "$start_modem"; # send "restarted" email open(III,"|/usr/lib/sendmail -t"); print III "From: $errormail\n"; print III "To: $adminmail\n"; print III "Subject: NET CONNECTION ERROR\n\n"; print III "At $errortime the net connection was"; print III "restarted by the errorhandler.\n"; close(III); }; # send minor glitch email open(IV,"|/usr/lib/sendmail -t"); print IV "From: $errormail\n"; print IV "To: $adminmail\n"; print IV "Subject: NET CONNECTION ERROR\n\n"; print IV "At $errortime there was a minor problem.\n"; print IV "No restart was necessary.\n"; close(IV); }; close(II); }; print "Test successfully completed at $errortime\n"; }; }; close(I);