#!/perl/bin/perl
#----------------------------------------------------------------------#
# This is a Freeware #
# #
# Perl name : checkping.pl #
# Programmers : Eli Ofek #
# #
# Description: Report on ping status, and send it using SMTP #
# This is perl, v5.6.0 built for MSWin32-x86-multi-thread#
# Invocation: #
# Please send filename , email address, smtp-mailserver #
# #
# #
# #
#----------------------------------------------------------------------#
# Modification history: #
# #
# Date Programmer Description #
# #
# 2001/08/15 Eli Ofek New program #
# #
# YYYY/MM/DD Your name here Short description of changes#
#----------------------------------------------------------------------#
#----------------------------------------------------------------------#
use Net::Ping;
use Net::SMTP;
my $Report;
my $from = 'Check_Ping_Reporter@EliOfek.co.il';
if ($#ARGV <2) { die "Not enough parameters, Please send filename , email address, smtp-mailserver \n\n";}
# Get Params
my $filename = $ARGV[0];
my $email = $ARGV[1];
my $mailserver = $ARGV[2];
# Get Url's
open (URLS,$filename) || die "Cannot open $filename \n\n";
my @host = <URLS>;
close(URLS);
print "Starting to ping...\n\n";
# Create a new ping object:
$p = Net::Ping->new();
foreach $host (@host)
{
chomp($host);
print "\nPinging $host ... ";
if (not $p->ping($host))
{
print "$host is dead.\n";
$Report = join("\n",$Report,"$host is dead.\n");
}
}
print "\n\nFinished to ping...\n\n";
# dispose ping object:
$p->close();
if (not ($Report eq "") )
{
# Send report using smtp:
print "Sending report to $email ...\n\n";
# Constructor
$smtp = Net::SMTP->new($mailserver);
# Compose mail:
$smtp->mail($ENV{USER});
$smtp->to($email);
$smtp->data();
$smtp->datasend("From: $from\n");
$smtp->datasend("To: $email\n");
$smtp->datasend("Subject: Checkping Reporter found dead url/s\n");
$smtp->datasend("\n");
$smtp->datasend($Report);
$smtp->dataend();
$smtp->quit;
print "Report was sent to $email ...\n\n";
}
print "Done.\n\n";
exit(0);