use strict; use Net::Ping; # Declare Var my ($host, $x, $res); my $output = ''; # Servers To Ping my @AFIS = qw( mnbcamp001 mnbcamp002 mnbcamp003 mnbcamp004 mnbcamp005 ); # Ping Hosts Defined Above sub ping_hosts { foreach $host (@AFIS) { my $p = Net::Ping->new("icmp"); my $res = $p->ping($host); $output .= "Unknown $host\n" unless defined $res; if (!$res) { $output .= "$host Host is not reachable!\n"; } else { $output .= "$host Host is reachable!\n" } } } ping_hosts; # Print Results to Terminal print $output; #### my $outfile = "output.txt"; open (OUTFILE, ">> $outfile") || die "ERROR: opening $outfile\n"; chomp ($host); print OUTFILE "Results for $host:\n"; print OUTFILE "$results\n\n";