Python Server Ping Script


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


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";
sysopen(FILEIN, $loc, O_RDONLY);
my @ip_array = <FILEIN>;
$p = Net::ping->new();
foreach (@ip_array) {
    if ($_ =~ /\d+.\d+.\d+.\d+/) {
        if ($p->ping($&)) {
                sendEmail("yourname\", "pinger\", "Server Online ($&).", "$& is online");
        } else {
                sendEmail("yourname\", "pinger\", "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, set a cronjob to run X minutes/hours.