Skip to content

Instantly share code, notes, and snippets.

@rankun203
Created May 5, 2019 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rankun203/7c72a105d5fa406a09472215e4606818 to your computer and use it in GitHub Desktop.
Save rankun203/7c72a105d5fa406a09472215e4606818 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
# ./ping-google.perl google.com
use Net::Ping;
my $host = "$ARGV[0]" || 'google.com';
my $p = Net::Ping->new('icmp');
my ($ret, $duration, $ip) = $p->ping($host);
say "Success(1): ${ret}";
say "Duration(s): ${duration}";
say "IP(of ${host}): ${ip}";
if ($ret == 0) {
say "Failed to connect to host ${host}";
$p->close();
exit -1;
} else {
$p->close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment