Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: PERL SCRIPT FOR IPv6 LOOK-UP

by sweetblood (Parson)
on Jun 08, 2010 at 17:13 UTC ( #843708=note: print w/ replies, xml ) Need Help??


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


Comment on Re: PERL SCRIPT FOR IPv6 LOOK-UP
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!"

        :-)

        ok then, can you help me out then with perl script suitable for the purpose mentioned. thanks
      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);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://843708]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2015-07-29 19:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls