http://www.perlmonks.org?node_id=843708


in reply to PERL SCRIPT FOR IPv6 LOOK-UP

In what way do you need help? Have you started this project? Do you have code that is giving you problems?

Sweetblood

Replies are listed 'Best First'.
Re^2: PERL SCRIPT FOR IPv6 LOOK-UP
by sam127 (Initiate) on Jun 08, 2010 at 17:37 UTC
    thanks for quick repsonse;i actually have 2codes that i got from the internet and trying but isnt working,here are they: here's the simple one that isnt working too;
    #!/bin/sh # # pinghosts - ping hosts in /home/olle/file2.txt, output is coloured ( +red=bad). Ver 1.00. # # for host in `awk '/^[0-9]/ { print $1 }' /home/ole/file2.txt` do echo "Checking $file2: \c" ping6 $host 1 2>&1 | \ sed 's/.*no answer.*/[31;1m& [0m/;s/.*is alive.*/[32;2m& [0m/' done
      This is not a perl script, it's a shell script.

      Sweetblood

        Well...

        The first one is a shell script; the second, "not so much!"

        :-)

      A reply falls below the community's threshold of quality. You may see it by logging in.
      heres the second code
      #!/usr/bin/perl use Net::Ping6; open(INFILE, "<", "/home/olle/file2.txt") or die("cannot open infile: + $!"); my @ip_array = <INFILE>; close(INFILE); open(OUTFILE, ">", "ping_output") or die("unable to write output: $!") +; chomp(@ip_array); $p = Net::Ping->new(); foreach(@ip_array) { if($_ =~ /\d+.\d+.\d+.\d+/) { if($p->ping6($&)) { print OUTFILE ("$`is responding to ping.\n"); } else { print OUTFILE ("$`is NOT responding to ping.\n"); } } } close(OUTFILE);
        In what way is this code not working for you? Be as detailed as possible. Use print as a debug tool to show the value of variables at different points in your code. See also: Basic debugging checklist.
        use Net::Ping6; ... if($p->ping6($&))
        If I drop the '6', and use Net::Ping, then change $` to $&, it works for me: the ping_output file shows the correct 'responding' message for the list of IP addresses I gave it.
        Just a note here, chances are that
        if($_ =~ /\d+.\d+.\d+.\d+/)
        won't be matching IPv6 addresses, since they are normally in hex, can you show us a sample of your file2.txt so we can help you better?

        Try this, it is working for me.

        #!/usr/bin/perl use Net::Ping; open(INFILE, "<", "d:\\file2.txt") or die("cannot open infile: $!"); my @ip_array = <INFILE>; close(INFILE); open(OUTFILE, ">", "d:\\ping_output") or die("unable to write output: +$!"); chomp(@ip_array); $p = Net::Ping->new(); foreach(@ip_array) { if($_ =~ /\d+.\d+.\d+.\d+/) { if($p->ping($&)) { print OUTFILE ("$_ is responding to ping.\n"); } else { print OUTFILE ("$_ is NOT responding to ping.\n"); } } } close(OUTFILE);