Sponsored Content
Top Forums Shell Programming and Scripting [ASK] How to check whether ipv4 or ipv6 and ping those IP Post 302531481 by franzramadhan on Friday 17th of June 2011 02:19:14 AM
Old 06-17-2011
[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
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

Last edited by franzramadhan; 06-17-2011 at 04:03 AM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

convert from ipv4 to ipv6

hello i'm working on aix 5300-05-03 hacmp ver 5.4 well my issue is that when firewall (gateway to internet ) goes down my machine start to work very very slowly!!! the output of the sniffer is that on the output card , my machine try to convert ipv4 to ipv6 0.0.2.0 my machine is not configure... (1 Reply)
Discussion started by: ariec
1 Replies

2. AIX

convert ipv4 ti ipv6

hello i'm working on AIX 5300-05-03 P520 hacmp 5.4 when connection to the internet is going down , firewall down, my application work verey verey slowly!!! and on the sliffer output i'm got trys of my serevr to do convert from ipv4 ipv6 ( 0.0.2.0 and AAAAAAAA). some one have an idea why... (1 Reply)
Discussion started by: ariec
1 Replies

3. IP Networking

How to configure Samba 3 for IPv6 operation with Window XP for IPv4

Need help...! I want to configure Samba 3 for IPv6 operation with Window XP for IPv4. I appreciate any guide. Thanks HSV (0 Replies)
Discussion started by: Sovan
0 Replies

4. Solaris

(Help) IPv6 tunneling over existing IPv4 in Solaris

Hi folks, i hope you'll help me to configure my ipv6 tunnel. First, i create my tunnel in: Hurricane Electric Free IPv6 Tunnel Broker My IP is 83.228.93.34 in HE: ------------------------ Server IPv4 address: 216.66.84.46 Server IPv6 address: 2001:470:1f14:16a::1/64 Client IPv4 address: ... (2 Replies)
Discussion started by: static
2 Replies

5. Red Hat

IPv4 and IPv6 Related Question to CentOS VMs

Hello, I was wondering if it would be possible to run two VMs one with services for IPv4 and the other one with services for IPv6. The main physical system would be connected to a IPv6 switch. I think it should be fine but I would like to hear out your comments. (1 Reply)
Discussion started by: svalenciatech
1 Replies

6. Solaris

ISC DHCP ipv4 and ipv6 options

Hi I am looking to set-up ISC DHCP to support ipv6, and to migrate my existing SUN DHCP ipv4 to ISC, finding the ipv4 options for the SUN DHCP options was ok eg TFTPsrvN = tftp-server-name OptBootF = bootfile-name However if I set up a DHCPv6 does anyone know what the equivalent... (1 Reply)
Discussion started by: eeisken
1 Replies

7. AIX

IPv6/IPv4 Only in AIX

Hi all, I have setup ipv6 in AIX machine using autoconf6 command. I was successfull in doing this. after execution of the command local link address was assigned to one of the interfaces (en1).But I have to setup the following environment as well. 1) Machine with only IPv6 support(IPv4... (0 Replies)
Discussion started by: ard
0 Replies

8. Solaris

Ntp between ipv4 and ipv6

Hi, I am looking for a solution to configure ntp between ipv4 ( ntp server ) to ipv6 ( client) . I had google, but lot many sites suggest to have dual stock or tunnaling. my issue is I have client has only ipv6 address ans server has ipv4 address. is it possible to sync time,... (4 Replies)
Discussion started by: naveen.surisett
4 Replies

9. Solaris

How to assign IPv4 and IPv6 addresses with same interface?

Hello dears how to assign IPv4 and IPv6 addresses with same interface on solaris 10 (1 Reply)
Discussion started by: ttashman
1 Replies
Net::Oping(3pm) 					User Contributed Perl Documentation					   Net::Oping(3pm)

NAME
Net::Oping - ICMP latency measurement module using the oping library. SYNOPSIS
use Net::Oping (); my $obj = Net::Oping->new (); $obj->host_add (qw(one.example.org two.example.org)); my $ret = $obj->ping (); print "Latency to `one' is " . $ret->{'one.example.org'} . " "; DESCRIPTION
This Perl module is a high-level interface to the oping library <http://verplant.org/liboping/>. Its purpose it to send "ICMP ECHO_REQUEST" packets (also known as "ping") to a host and measure the time that elapses until the reception of an "ICMP ECHO_REPLY" packet (also known as "pong"). If no such packet is received after a certain timeout the host is considered to be unreachable. The used oping library supports "ping"ing multiple hosts in parallel and works with IPv4 and IPv6 transparently. Other advanced features that are provided by the underlying library, such as setting the data sent, are not yet supported by this interface. INTERFACE
The interface is kept simple and clean. First you need to create an object to which you then add hosts. Using the "ping" method you can request a latency measurement and get the current values returned. If necessary you can remove hosts from the object, too. The constructor and methods are defined as follows: $obj = Net::Oping->new (); Creates and returns a new object. $status = $obj->timeout ($timeout); Sets the timeout before a host is considered unreachable to $timeout seconds, which may be a floating point number to specify fractional seconds. $status = $obj->ttl ($ttl); Sets the Time to Live (TTL) of outgoing packets. $ttl must be in the range 1 ... 255. Returns true when successful and false when an error occurred. $status = $obj->bind ($ip_addr); Sets the source IP-address to use. $ip_addr must be a string containing an IP-address, such as "192.168.0.1" or "2001:f00::1". As a side-effect this will set the address-family (IPv4 or IPv6) to a fixed value, too, for obvious reasons. $status = $obj->device ($device); Sets the network device used for communication. This may not be supported on all platforms. Requires liboping 1.3 or later. $status = $obj->host_add ($host, [$host, ...]); Adds one or more hosts to the Net::Oping-object $obj. The number of successfully added hosts is returned. If this number differs from the number of hosts that were passed to the method you can use get_error (see below) to get the error message of the last failure. $status = $obj->host_remove ($host, [$host, ...]); Same semantic as host_add but removes hosts. $latency = $obj->ping () The central method of this module sends ICMP packets to the hosts and waits for replies. The time it takes for replies to arrive is measured and returned. The returned scalar is a hash reference where each host associated with the $obj object is a key and the associated value is the corresponding latency in milliseconds. An example hash reference would be: $latency = { host1 => 51.143, host2 => undef, host3 => 54.697, ... }; If a value is "undef", as for "host2" in this example, the host has timed out and considered unreachable. $dropped = $obj->get_dropped () Returns a hash reference holding the number of "drops" (echo requests which were not answered in time) for each host. An example return values would be: $droprate = { host1 => 0, host2 => 3, host3 => undef, ... }; Hosts to which no data has been sent yet will return "undef" ("host3" in thie example). $ttl = $obj->get_recv_ttl () Returns a hash reference holding the Time to Live (TTL) of the last received packet for each host. An example return value would be: $ttl = { host1 => 60, host2 => 41, host3 => 243, ... }; To signal an invalid or unavailable TTL, a negative number is returned. $errmsg = $obj->get_error (); Returns the last error that occurred. CAVEATS
The oping library opens a raw socket to be able to send ICMP packets. On most systems normal users are not allowed to do this. This is why on most systems the ping(1) utility is installed as SetUID-root. Since, when using this module, no external process is spawned this process needs the appropriate permissions. This means that either your script has to run as superuser or, under Linux, needs the "CAP_NET_RAW" capability. SEE ALSO
liboping(3) The liboping homepage may be found at <http://verplant.org/liboping/>. Information about its mailing list may be found at <http://mailman.verplant.org/listinfo/liboping>. AUTHORS
First XS port by Olivier Fredj, extended XS functionality and high-level Perl interface by Florian Forster. COPYRIGHT AND LICENSE
Copyright (C) 2007 by Olivier Fredj <ofredj at proxad.net> Copyright (C) 2008,2009 by Florian Forster <octo at verplant.org> This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available. Please note that liboping is licensed under the GPLv2. Derived works of both, Net::Oping and liboping, (i. e. binary packages) may therefore be subject to stricter licensing terms than the source code of this package. perl v5.14.2 2012-01-31 Net::Oping(3pm)
All times are GMT -4. The time now is 04:11 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy