Last active
May 1, 2019 01:37
-
-
Save yeahnoob/ede52dd6406c9d04c544 to your computer and use it in GitHub Desktop.
Ping & Log
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use Net::Ping; | |
use Time::HiRes; | |
$host = $ARGV[0]; | |
while (1) { | |
open $fd, '>>:encoding(UTF-8)', 'ping.pl.log'; | |
$p = Net::Ping->new("icmp"); | |
$p->hires(); | |
($ret, $duration, $ip) = $p->ping($host, 2); #config ping timeout=2sec. | |
print $fd scalar(localtime); | |
print $fd "\n"; | |
print $fd sprintf("$host [ip: $ip] is alive (delay: %.2f ms)\n", 1000 * $duration) if $ret; | |
$p->close(); | |
close $fd; | |
sleep 1; #waiting time between two "ping" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment