I have written perl ping program to ping list of IPs one by one and print the status.But each and every time it is showing the status as Pass for all IPs even though the IP is wrong.
multipleip.pl
use Net::Ping;
$p = Net::Ping->new();
$ifile="inventory.txt";
open(IP,$ifile) or die("Not able to open the file");
@data_count=(<IP>);
for($i=0;$i<=$#data_count;$i++)
{
my $host=$data_count;
if ($p->ping($host))
{
print "Pass\n";
}
else
{
print "Fail...\n";
}
}
$p->close();
ips.txt
173.252.110.27
173.2522.110.27
8.25.218.11
8.258.218.11
But the same program is working fine for single IP.
use Net::Ping;
$p = Net::Ping->new();
my $host = "8.25.218.11";
# print "$host is alive.\n" if $p->ping($host);
if ($p->ping($host))
{
print "success";
}
else
{
print "Fail";
}
$p->close();
Could you please let me know what went wrong with the multipleip.pl program
Regards,
John
---------- Post updated at 06:18 AM ---------- Previous update was at 05:23 AM ----------
trying my level best but not albe to solve this...Any help on this is much appreciated...