DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Perl (http://www.daniweb.com/forums/forum112.html)
-   -   Perl Ping Help (http://www.daniweb.com/forums/thread31064.html)

rharsha83 Aug 24th, 2005 10:37 am
Perl Ping Help
 
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...

kordaff Sep 1st, 2005 6:24 pm
Re: Perl Ping Help
 
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

Jayaprabhu Oct 11th, 2006 3:46 pm
Re: Perl Ping Help
 
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";
}




All times are GMT -4. The time now is 4:50 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC