sgarc90 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Net::Ping I have only just started to create the script and already have encountered errors. Here is the error I have received: "Can't get tcp echo port by name at pingTest.pl line 6"

SOURCE CODE ( so far):

use Net::Ping; use strict; my $p; my $host = '192.168.254.254'; $p = Net::Ping->new();
This really should be a simple task. I am using activePerl on WinXP. thanks in advance Sam

Replies are listed 'Best First'.
Re: Ping error on WinXP
by bluescreen (Friar) on Jun 18, 2010 at 02:40 UTC

    The Net::Ping croaking in the following line

    $self->{"port_num"} = (getservbyname('echo', 'tcp'))[2] ||

    So I'm affraid that echo service is not defined in the services file ( c:\windows\system32\drivers\etc\services ), you might want to add echo service there which BTW uses port 7

    I don't know what are you trying to do, but if I'm guessing correctly you only want to get the status of a host using regular ICMP pings ( like command line's ping ), in order to use icmp you have to specify that in the Net::Ping's constructor

    use strict; use warnings; use Net::Ping; my $ping = Net::Ping->new('icmp'); if ( $ping->ping('127.0.0.1') ) { print "alive\n"; } else { print "dead\n"; }
Re: Ping error on WinXP
by ww (Archbishop) on Jun 18, 2010 at 02:33 UTC
    Perhaps we can give better help if you'll give us some more information. Which version of perl: ActiveState, Strawberry, other?</fingers-faster-than-brain>? Which vers of Net::Ping? Do you have a server active at the IP shown? Anything else that might contribute to your problem?

    I can't get any version of W32 I have avail (W2k w/5.10.1; vista w/5.8.n) to reproduce the message you're showing us. And what you're showing (as perhaps you know) would produce no output other than an error or warning.

    Changing the IP to one of mine and adding (along with use warnings) the following (directly from the synopsis):

    print "$host is alive.\n" if $p->ping($host); $p->close();

    returns the expected result: namely that (my IP) is alive. Simply trying to print $p indicates that $p is (again, as expected) a reference to a hash:

    $p: Net::Ping=HASH(0x15d5020)

    And just in case the reference the "the synopsis" is a mystery, try:

    perldoc Net::ping

    hth ... to some small degree

Re: Ping error on WinXP
by sgarc90 (Initiate) on Jun 18, 2010 at 03:17 UTC
    I have a 155 routers that I need to verify are connected to the WAN. I do not relish the idea of having to manually ping from a command line each one. I only need to know if the device is reachable. By using the example from "blueScreen" I was able to ,finally, run the script. I am a budding network analyst. I can see perl quickly becoming a valued tool in my growing toolbox.

    Thank you all for the help.