Python Server Ping Script

deluxehost

New Member
Here is what i use for my online checker, its perl and requires sendmail. but here it is


#!/usr/bin/perl


use Net::ping;
use Fcntl;
$loc = "hosts";
sub sendEmail
 {
  my ($to, $from, $subject, $message) = @_;
        my $sendmail = '/usr/lib/sendmail';
        open(MAIL, "|$sendmail -oi -t");
                print MAIL "From: $from\n";
                print MAIL "To: $to\n";
                print MAIL "Subject: $subject\n\n";
                print MAIL "$message\n";
        close(MAIL);
 }
sysopen(FILEIN, $loc, O_RDONLY);
my @ip_array = <FILEIN>;
chomp(@ip_array);
$p = Net::ping->new();
foreach (@ip_array) {
    if ($_ =~ /\d+.\d+.\d+.\d+/) {
        if ($p->ping($&)) {
                sendEmail("yourname\@gmail.com", "pinger\@yourdomain.com", "Server Online ($&).", "$& is online");
        } else {
                sendEmail("yourname\@gmail.com", "pinger\@yourdomain.com", "Server Offline ($&).", "$& is offline.");
        }
    } else {
#        print " ip address is not valid $_\n";
    }
}
All you do is save your IPs in the file hosts as the same directory as serverstatus.pl, set a cronjob to run X minutes/hours.
 
Top