#!/usr/bin/perl -w
#edit: www.jb200.com
use Net::Ping;
use Net::SMTP;
use MIME::Base64;
my @host_array=('192.168.0.10','192.168.0.11');
my $p = Net::Ping->new("icmp");
foreach $host (@host_array)
{
# print "$host is ";
unless($p->ping($host,2))
{
&
sendmail($host." is down",$host." is down");
}
# print "n";
# print "NOT " unless $p->ping($host, 2);
# print "reachable.n";
sleep(1);
}
sub sendmail(){
my $mailhost = "smtp server domain"; # the smtp host
my $mailfrom = 'your email address'; # your email address
my $mailto='email address you want to send';
my $subject=$_[0];
my $text = $_[1];
$smtp = Net::SMTP->new($mailhost, Hello => 'localhost', Timeout =>120, Debug => 1);
$smtp->auth('user name','password');
$smtp->mail($mailfrom);
$smtp->to($mailto);
$smtp->data();
$smtp->datasend("Content-Type:text/html;charset=utf-8n");
$smtp->datasend("Content-Transfer-Encoding:base64n");
$smtp->datasend("To:=?utf-8?B?".encode_base64($mailto,'')."?= <$mailto> n");
$smtp->datasend("From:=?utf-8?B?".encode_base64($mailfrom,'')."?= <$mailfrom> n");
$smtp->datasend("Subject:=?utf-8?B?".encode_base64($subject,'')."?=nn");
$smtp->datasend("n");
$smtp->datasend(encode_base64($text,'')." n");
$smtp->dataend();
}
$p->close();