in reply to Re^7: using online translation engines with perl (ping)
in thread using online translation engines with perl

That I can't reach google with Net::Ping is a head-scratcher.

Indeed it is. I'm unable to reproduce that. Perhaps this pared-down test would be a starting point?

use strict; use warnings; use Net::Ping; use Test::More tests => 2; my $dest = 'www.google.com'; my $pinger = Net::Ping->new ('icmp', 3); my $res; $res = system ("ping -nqc1 -w 3 -W 3 $dest > /tmp/ping.log"); is ($res, 0E0, "System ping to $dest"); $res = $pinger->ping ($dest); ok ($res, "Net::Ping to $dest"); $pinger->close;

Running this I see the expected output.

$ sudo prove -v googleping.t googleping.t .. 1..2 ok 1 - System ping to www.google.com ok 2 - Net::Ping to www.google.com ok All tests successful. Files=1, Tests=2, 1 wallclock secs ( 0.05 usr 0.01 sys + 0.05 cusr + 0.01 csys = 0.12 CPU) Result: PASS

If you can run this and pass one test but not the other, I suggest firing up wireshark and see what's actually happening on the network. Good luck.

Replies are listed 'Best First'.
Re^9: using online translation engines with perl (ping)
by Aldebaran (Curate) on Nov 30, 2018 at 00:28 UTC
    Perhaps this pared-down test would be a starting point?

    I can't get anything from Net::Ping, likely because I understand less than half of it. To my way of the thinking, it is "actually" the system that pings, and the perl module that wraps this call. (Is that wrong?) If I can do that with a straight-up system call, then that's what they are for.

    I hadn't used prove before, so I was glad to see how this goes:

    $ sudo prove -v 5.ping3.pl [sudo] password for bob: 5.ping3.pl .. 1..2 ok 1 - System ping to www.google.com not ok 2 - Net::Ping to www.google.com # Failed test 'Net::Ping to www.google.com' # at 5.ping3.pl line 14. # Looks like you failed 1 test of 2. Dubious, test returned 1 (wstat 256, 0x100) Failed 1/2 subtests Test Summary Report ------------------- 5.ping3.pl (Wstat: 256 Tests: 2 Failed: 1) Failed test: 2 Non-zero exit status: 1 Files=1, Tests=2, 11 wallclock secs ( 0.04 usr 0.02 sys + 0.14 cusr + 0.03 csys = 0.23 CPU) Result: FAIL $ cat 5.ping3.pl #!/usr/bin/perl -w use 5.011; use Net::Ping; use Test::More tests => 2; my $dest = 'www.google.com'; my $pinger = Net::Ping->new ('icmp', 10); my $res; $res = system ("ping -nqc1 -w 3 -W 3 $dest > /tmp/ping.log"); is ($res, 0E0, "System ping to $dest"); $res = $pinger->ping ($dest); ok ($res, "Net::Ping to $dest"); $pinger->close; $ ping -nqc1 -w 3 -W 3 www.google.com PING www.google.com(2607:f8b0:400a:800::2004) 56 data bytes --- www.google.com ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 24.338/24.338/24.338/0.000 ms $

    So the problem exists somewhere between my chair and the operating system. But I've got a version that works, so I can just use that. Why play bad logic games? Between the following readmore tags are output, then source, including a template that provides monastery tags, and the output of the system command appended in that same, unique, time-based file:

    I'm happy with this result from this thread. Thank you for your comments.

    If you can run this and pass one test but not the other, I suggest firing up wireshark and see what's actually happening on the network.
    sudo add-apt-repository ppa:wireshark-dev/stable sudo apt-get update sudo apt-get install wireshark sudo wireshark

    Eye-popping software. Thx.

      You might want to give Net::Ping::External a try. From its docs:

      ... this module will probably provide more accurate results than Net::Ping will. Why? ICMP ping is the most reliable way to tell whether a remote host is alive. However, Net::Ping cannot use an ICMP ping unless you are running your script with privileged (AKA "root") access. The system's "ping" command uses ICMP and does not usually require privileged access.