[ASK] How to check whether ipv4 or ipv6 and ping those IP

I have perl script that I use to check and ping a list of ip,
The problem is, I didnt understand how to ping ipv6 on perl,
Could I use Ping::External??And how could I get the ping result (reply or not)?

This is my code

#!/usr/bin/perl --
use Net::Ping;
use Data::Validate::IP;
use Time::HiRes;
$own       = qx(perl /opt/probing/cekip.pl);
$ownhost   = hostname;
@host      = $ARGV[0];
for ( $x = 1 ; $x <= 49 ; $x++ ) {
    $time = [Time::HiRes::gettimeofday];
    $starttime =
      Time::HiRes::tv_interval( $time, [Time::HiRes::gettimeofday] ) * 1000;
    $ping = Net::Ping->new("icmp");
    $endtime =
      Time::HiRes::tv_interval( $time, [Time::HiRes::gettimeofday] ) * 1000;
    $waktu  = $endtime - $starttime;
    $waktu1 = $waktu1 + $waktu;
    foreach $host2 (@host) {
        if ( is_ipv4($host2) ) {
            unless ( $ping->ping($host2) ) {
                    #print "error:$host", scalar(localtime), "\n";
                $lost = $lost + 1;
            }
            else {

                #print "success:$host", scalar(localtime), "\n";
                $lost    = 0;
                $sent    = $x;
                $receive = $receive + 1;
                if ( $waktu > $max1 ) {
                    $max1 = $waktu;
                    $max = sprintf( "%.2f", $max1 );
                }
                if ( $waktu < $min1 ) {
                    $min1 = $waktu;
                    $min = sprintf( "%.2f", $min1 );
                }
            }
        }
        if ( is_ipv6($host2) ) {
           // Still Blank Here..
            }
        }

Thanks in advance,
Franz

Not sure if there is a Net::Ping6... but you can try using AnyEvent::FastPing, it's designed to ping a large range of hosts, but I suppose it could be limited to one. It supports IPv6.

1 Like

Thanks for your response,
My question, how could I get the ping result? RTO, Unreachable or reply?
Because I must get it on some log files based on ip addresses
And, what is the function of AnyEvent::Socket ?? Could you explain to me?
Sorry for being too pry of this..

Thanks in advance
Franz

I have tried your solution, but it doesnt seem to be running.But I have an idea, to get ping result from ping6 command from linux it self. The problem is, I still dont understand how to grep the ping result from this command, whether reply,request timed out, or destination unreachable? Somebody told me to use regex on perl. But I still confused, what kind of regex that I have to use..
Any solutions??

Thanks in advance,
Franz