#!/usr/local/bin/perl use strict; use warnings; use Net::Ping; use Net::SMTP; my $from = 'from@email.com'; my $site = 'email.com'; my $smtp_host = 'smtp.email.com'; my $to = 'to@email.com'; my $smtp = Net::SMTP->new($smtp_host, Hello => $site); my $oFile = open(oFILE, ">", "output.file") or die("unable to write to $!\n"); my $hFile = open(hFILE, "<", "host.file") or die("unable to open $!\n"); my @ip_array = ; chomp(@ip_array); my $eFile = open(eFILE, ">", "email.file") or die("unable to write to $!\n"); my @efile = ; chomp(@efile); sub email { $smtp->mail($from); $smtp->to($to); $smtp->data(); $smtp->datasend("To: $to\n"); $smtp->datasend("Subject: Ping failure notice.\n"); $smtp->datasend("\n"); $smtp->datasend("Ping failed on host $_\n"); $smtp->dataend; print eFILE ("$_\n"); } my $p = Net::Ping->new(); foreach (@ip_array) { if($p->ping($_)) { print oFILE ("$_ is responding to ping.\n"); } else { print oFILE ("$_ is NOT responding to ping.\n"); unless ($_ =~ my @eFile) { email(); } } } close(hFILE); close(oFILE); close(eFILE); $p->close(); $smtp->quit; #End of Code