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

Hello, I am trying to write Perl code to ping an ipv6 machine, and have bellow code which fails to ping. Need your help to understand correct flow. I am using 2.63 version of Net::ping
#!/usr/bin/perl use Net::Ping; my $host = 'Virt-titan-26'; my $pings_timeout = 15; # seconds print("Pinging host [$host]...\n"); # Modified ping to accept $family(ipv6) as seson parameter my $ping = Net::Ping->new('icmpv6', 'ipv6'); $ping->hires(1); my $single_ping_timeout = 5.0; # seconds my $pings_start_time = time; while (1) { my ($ret, $pingtime, $ip) = $ping->ping($host, $single_ping_timeout) +; my $pings_duration = time - $pings_start_time; # print("\n\n\nAnand : $ip\n\n\n\n"); if ($ret) { print("Host [$host ($ip)] responded to ping \n"); last; } else { print("\nHost [$host ($ip)] did NOT respond to ping \n"); } if ($pings_duration >= $pings_timeout) { print("\nHost [$host ($ip)] did not respond to any pings within +timeout of \n"); exit; } print("\nSleep\n"); sleep(1); } print("\nVerified ping connectivity to host \n");
------------------- Output:
C:\Users\Administrator>perl C:\test-ping.pl Pinging host [Virt-titan-26]... Host [Virt-titan-26 (xxxx)] did NOT respond to ping Sleep Host [Virt-titan-26 (xxx)] did NOT respond to ping Sleep Host [Virt-titan-26 (xxx)] did NOT respond to ping Host [Virt-titan-26 (xxx)] did not respond to any pings within timeout + of

Replies are listed 'Best First'.
Re: IPV6 ping code not working
by hippo (Archbishop) on Nov 30, 2017 at 14:53 UTC
    my $ping = Net::Ping->new('icmpv6', 'ipv6');

    That is not a valid call to the constructor:

    $ perl -MNet::Ping -e 'my $ping = Net::Ping->new(q/icmpv6/, q/ipv6/);' Protocol for ping must be "icmp", "udp", "tcp", "syn", "stream", or "e +xternal" at -e line 1.

    at least not in version 2.43 which is what I have installed here.

      Following code with 2.63
      IPV4 ping # perl -MNet::Ping -e 'my $ping = Net::Ping->new(q/icmp/, 10,q//,q//,q +//,q//,q/ipv4/);print("ping successfull") if $ping->ping(q/Virt-titan +-17/)' ping successfull IPV6 ping perl -MNet::Ping -e 'my $ping = Net::Ping->new(q/icmpv6/, 10,q//,q//,q +//,q//,q/ipv6/);print("ping successfull") if $ping->ping(q/Virt-titan +-17/)' ' virt-titan-17:~ #

        Looks like there is a bug report open for this. Check the latest comment (6th Aug 2017) which also includes a proposed patch that you might like to test.

        Does the hostname virt-titan-17 actually resolve to a v6 address?

        In other words, can you successfully ping6 virt-titan-17 successfully?