A script I wrote that checks whether a host is reachable by various protocols like ICMP & TCP.

Posted: February 20, 2013. At: 9:06 AM. This was 4 years ago. Post ID: 5393

#!/usr/bin/perl
 
use warnings;
 
use Net::Ping;
 
# code source: http://www.perlmonks.org/?node_id=943892
# More: http://stackoverflow.com/questions/3960595/how-can-i-ping-a-host-with-a-perl-one-liner-with-netping
 
#$| = 1;
print "Please type a host to check..n";
$host = <>;
 
if (length($host) < 3) {
    print "You did not type a host!n";
    exit(0);
}
 
my @proto = ("tcp", "udp", "icmp", "stream", "syn");
 
foreach my $pro ( @proto ) {
    print "nProtocol $pro n";
    my $p = Net::Ping->new($pro);
    chomp($host);
    # Specify source interface of pings
    print "$host is ";
    print "NOT " unless $p->ping($host, 2);
    print "reachable.n";
    $p->close();
}
 
exit(0);

This Perl script will check whether a web host is up using a handful of protocols to ping the host. Very useful script. This requires root access.

No comments have been made. Use this form to start the conversation :)

Leave a Reply