0

hi,
i have been asked to get the information of the systems in the network by executing ping in perl programming.

use Net::Ping;
$p = Net::Ping->new();
print "$host is alive.\n" if $p->ping($host);
$p->close();

sample of my code is shown above

where $host--> is the ip of the destination machine. if i try to give the loopback or ip of my machine then its working properly. but if i try to give ip of the some other machine conneted to network then ping will not work.
But ping using command prompt is working properly for any machine in the network.
Is there anybody to help me out...

3
Contributors
2
Replies
3
Views
12 Years
Discussion Span
Last Post by Jayaprabhu
0

Net::Ping defaults to a tcp connection to the echo port (7 according to my /etc/services file). Use this (from the Net::Ping man page) example to do a regular ICMP ping like the command line:

use Net::Ping;
my $p = Net::Ping->new('icmp');
print "$host is ";
print "NOT " unless $p->ping($host, 2);
print "reachable.\n";
sleep(1);
$p->close();

Kordaff

0

Try this... Its working for me

my $a;
my $p;
use Net::Ping;
$p = Net::Ping->new();
$a= $p->ping("$host");
$p->close();
if( $a eq '')
{
print "Host is not alive";
}
else
{
print "Host is alive";
}


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.