Hey Folks, I'm having some trouble parsing the results generated by Nmap::Scanner and was hoping you guys could help out. Here's what I've got:

use Nmap::Scanner; use Data::Dumper; my $scanner = new Nmap::Scanner; $scanner->tcp_connect_scan(); $scanner->add_scan_port('1-1024'); $scanner->max_rtt_timeout(3); $scanner->add_target('127.0.0.1'); my $results = $scanner->scan(); print Dumper($results->{'ALLHOSTS'});

The dump suggests that the output is a hash (I think) with the key Nmap::Scanner::Address=Hash(0x1231234). The problem I'm having is reliably accessing the contents of that key since every time the program runs, I get a different hash address. The solution I have so far is to do something like:

for my $key (keys $results->{'ALLHOSTS'}){ print Dumper($results->{'ALLHOSTS'}{$key}->{'ports'}); }
This allows me to retrieve the values associated with the key (e.g. ports info), but it can't be the best way to do it. What would you suggest as an alternative? EDIT: Thanks for the help everyone. It gave me a better understanding of what I was trying to do and gave me a few new tools to look into. Much appreciated.

In reply to Parsing output from Nmap::Scanner with varying hash address. by mopmeat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.