#!/usr/bin/perl use strict; use warnings; use Net::Ping; my @hosts = qw/host1 host2 host3 pcbackup/; # my $net="myhost\.com"; # unused for now my $proto="icmp"; my $p = Net::Ping->new($proto); my @uphosts=(); my @downhosts=(); foreach my $host(@hosts) { if ($p->ping($host)) { push (@uphosts, $host); } else { push (@downhosts, $host); } } $p->close(); $#downhosts++; $#uphosts++; print "There are $#downhosts hosts down\n"; print "There are $#uphosts hosts alive\n\n"; print "The following hosts are alive: \n"; foreach my $item (@uphosts) { print "$item\n"; } print "\nThe following hosts are down: \n"; foreach my $item (@downhosts) { print "$item\n"; }