Skip to content

Instantly share code, notes, and snippets.

@YUChoe
Last active August 29, 2015 14:08
Show Gist options
  • Save YUChoe/80cf6d879ad95f76cfb4 to your computer and use it in GitHub Desktop.
Save YUChoe/80cf6d879ad95f76cfb4 to your computer and use it in GitHub Desktop.
ping with perl
#!/usr/bin/perl
use Net::Ping;
use POSIX;
if ($#ARGV == -1) { die "Usage: pinglog {ip address} \n"; }
$host = $ARGV[0];
$ping = Net::Ping->new("icmp", 2);
$status = "Dead";
while (1) {
$old_status = $status;
$datestring = strftime "%a %b %e %H:%M:%S %Y", localtime;
if ($ping->ping("$host")) {
$status = "Alive";
} else {
$status = "Dead";
}
if ($old_status ne $status) {
print "$datestring '$host' is $status\n";
}
if ($status == "Alive") { sleep(2); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment