Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: PERL SCRIPT FOR IPv6 LOOK-UP

by sam127 (Initiate)
on Jun 08, 2010 at 17:39 UTC ( #843712=note: print w/replies, xml ) Need Help??


in reply to Re^2: PERL SCRIPT FOR IPv6 LOOK-UP
in thread PERL SCRIPT FOR IPv6 LOOK-UP

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);

Replies are listed 'Best First'.
Re^4: PERL SCRIPT FOR IPv6 LOOK-UP
by toolic (Bishop) on Jun 08, 2010 at 17:49 UTC
    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.
Re^4: PERL SCRIPT FOR IPv6 LOOK-UP
by AndyZaft (Friar) on Jun 08, 2010 at 20:23 UTC
    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?
Re^4: PERL SCRIPT FOR IPv6 LOOK-UP
by Generoso (Parson) on Jun 08, 2010 at 20:25 UTC

    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://843712]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2017-10-20 18:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My fridge is mostly full of:

















    Results (266 votes). Check out past polls.

    Notices?