#!/usr/bin/perl
use Net::Ping;
use strict;

my $host="111.111.111.111";

my $timeout=3; # timeout in seconds
my $p;
my $ltime;
my $flag;

select((select(STDOUT), $| = 1)[0]); #Set AutoFlush

for(;;){
$p = Net::Ping->new('icmp', $timeout);
# 'udp' - default, 'icmp' - must be root, 'tcp' - generates more traffic
# if you pping in a loop add a time delay to prevent generating DoS attack
if (($flag ne "connected") and ($p->ping($host))){
	$ltime=localtime;	#Get the Currenttime
	print "$ltime: $host is connected.\n";
	$flag="connected";
	}
elsif (($flag eq "connected") and !($p->ping($host))){
	$ltime=localtime;
	print "$ltime: $host is down or unreachable.\n";
	$flag="notconnected";
	}
$p->close();
sleep(10);	#sleep for 10 seconds
}
