Hi Noosrep,

I'd say the first step would be to narrow down more closely where the slowdown is happening. Insert some print statements to figure it out, and then narrow down the code to the minimum needed to reproduce the problem. See also Short, Self Contained, Correct Example.

I had a quick look at Nmap::Parser, and as far as I can tell it's just fetching information out of its internal data structures, which I'm guessing are just the result of parsing the XML file, and I haven't yet seen anything that would explain the slowdown. Looking at your code, the only thing that jumps out at me is the call to nslookup, since I'm guessing that's a network operation, which can cause delays.

Update: Looked at the Nmap::Parser source again, and it indeed looks like it's just looking stuff up in its data structures and not performing network operations. So aside from my nslookup theory above, it really would be best if you could identify the slow part of your code. Also, look at your loop logic:

foreach my $ip (@IPsinrange) { for my $host_obj ($np->all_hosts()) { if ($host_obj->ipv4_addr() eq $ip) { foreach my $port (@ports) {

So if your scan contains a lot of hosts, that could be a lot of looping. I'm guessing not enough to cause your script to run for 20 minutes, but I'd still suggest this logic as being a little more optimal:

my %IPsinrange = map {$_=>1} @IPsinrange; for my $host_obj ($np->all_hosts()) { next unless $IPsinrange{$host_obj->ipv4_addr()}; for my $port (@ports) {

Hope this helps,
-- Hauke D


In reply to Re: NMAP Parser very slow (updated) by haukex
in thread NMAP Parser very slow by Noosrep

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.