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...

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

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";
}


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.