[San-diego-pm] Re: Welcome to the "San-diego-pm" mailing list

Emile Aben emileaben at yahoo.com
Mon May 24 15:21:31 CDT 2004


Hi,

--- Bob Kleemann <rkleeman at energoncube.net> wrote:
> You may have noticed this in your inbox.  More
> importantly, you may have
> noticed the posting address has changed.  Update
> your records
> accordingly.

I indeed got the 'welcome' message, together with a
'could not deliver' on the old address because I
answered Dirks question on Net::Ping this weekend.
This explains why I got the 'could not deliver'.
Here's my answer again:

Hi Dirk,

By default Net::Ping doesn't use the same protocol as
the 'ping' utility. Net::Ping uses TCP port 7 (echo)
while 'ping' uses ICMP. I don't think www.yahoo.com
answers the TCP port 7 requests while it answers the
ICMP request.
A script that works for me (shamelessly stolen/adapted
from the Net::Ping documentation, see 'perldoc
Net::Ping'):
-------------------
use Net::Ping;
my $p = Net::Ping->new("tcp", 2);
my $host = "www.yahoo.com";
$p->{port_num} = getservbyname("http", "tcp");
 print "$host is alive.\n" if $p->ping($host);
$p->close();
--------------------
This script connects to the HTTP port (tcp/80) of
www.yahoo.com instead of ECHO port (tcp/7).

I think Net::Ping doesn't use the ICMP port by default
because you need superuser privileges to create ICMP
packets (the ping utility itself uses the setuser_id
mechanism to get elevated privileges, but thats
something thats not advisable in perl).

hope this helps,
Emile

--- Dirk2 <Dirk at finches.com> wrote:
> ~sdpm~
> Perl Mongers,
> 
> Why can't we ping from inside a Perl script? 
> Anything obvious I'm 
> missing here?
> 
> ~: uname -a
> Linux localhost.localdomain 2.4.21-15.EL #1 Thu Apr
> 22 00:26:34 EDT 2004
> i686 athlon i386 GNU/Linux
> 
> That's Red Hat Enterprise Linux ES (v. 3 for x86)
> 
> 
> 
> 
> 
> Here's the script that fails:
> ________________________________________
> #!/usr/bin/perl -w
> 
> use Net::Ping;
> 
> if ( pingecho("www.yahoo.com", 2) ) {
>     print "Yahoo is on the network.\n";
> }
> ________________________________________
> 
> 
> 
> 
> But ping on the command line works fine:
> 
> ~: ping www.yahoo.com
> PING www.yahoo.akadns.net (66.94.230.36) 56(84)
> bytes of data.
> 64 bytes from p5.www.scd.yahoo.com (66.94.230.36):
> icmp_seq=0 ttl=49
> time=22.1 ms
>  
> --- www.yahoo.akadns.net ping statistics ---
> 1 packets transmitted, 1 received, 0% packet loss,
> time 0ms
> rtt min/avg/max/mdev = 22.109/22.109/22.109/0.000
> ms, pipe 2





	
		
__________________________________
Do you Yahoo!?
Friends.  Fun.  Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/ 



More information about the San-Diego-pm mailing list