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.