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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |