Posted: . At: 9:06 AM. This was 11 years ago. Post ID: 5393
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

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

A nice script that will check if a host is up or not.

#!/usr/bin/perl
 
use warnings;
use strict;
 
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";
my $host = <>; #Reading input from STDIN.
 
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 "#-Protocol $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.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.