I have written a code to ping remote sites:
-----------------------------------
use strict;
use warnings;
use Socket;
use Net::Ping;
print 'Enter a hostname/IP ';
my $ip,my $host;
$ip=<STDIN>;
chomp($ip);
if ($ip =~ /\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/)
{
my $p = Net::Ping->new() or die "Can't create new ping object: $!\n";
if ($p->ping($ip)) { print "$ip is alive"; $p->close; exit;} else {print
"$ip is not alive";exit;}
}
else
{
$host=gethostbyname($ip);
chomp($host);
my $aip=inet_ntoa($host);
my $p = Net::Ping->new() or die "Can't create new ping object: $!\n";
if ($p->ping($aip)) {print "$aip is alive";} else {print "$aip is not
alive";}
$p->close;exit;
}
------------------------------------------------------------------------
If I run the code and ping www.yahoo.com, it resolves the hostname to
ip, and then it says it is NOT alive.
If I ping the same IP using the Ping utility, it is definitely replying.
Whats wrong?
C:\Documents and Settings\Gunnu\Desktop\Code\Gen 2>ping.pl
Enter a hostname/IP www.yahoo.com
87.248.113.14 is not alive
C:\ping 87.248.113.14
Pinging 87.248.113.14 with 32 bytes of data:
Reply from 87.248.113.14: bytes=32 time=188ms TTL=49
Reply from 87.248.113.14: bytes=32 time=207ms TTL=49
Thanks
--
Gunwant Singh.
"What is the sound of Perl?
Is it not the sound of Wall that people bang their heads against?"
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/