When I delete the section of tcp ports, the script runs without any speed problems. However, as soon as I want to parse the tcp ports output, the script takes very long. For instance a range of 4 addresses takes up to 20 minutes for the script to complete. That's doable but with a /24, this is simply too long. Now I have read that this kind of nmap port scanning takes a long time but is there something wrong with my code that makes it very slow? Perl newbie here so I think that could be the case :)my @IPsinrange = &getAllIPs($range) ; my $np = new Nmap::Parser; $np->parsefile('/home/users/axiroot/scripts/monitor-client/tmp/nmap.xm +l'); #using filenames my $si = $np->get_session(); #my @MACsinrange = &getAllMACs($range,) foreach my $ip (@IPsinrange) { $output .= "<tr>\n" ; $output .= "<th>$ip</th>\n" ; for my $host_obj ($np->all_hosts()){ if ( $host_obj->ipv4_addr() eq $ip ){ my $state = ""; $state = $host_obj->status() ; if ( $state eq "up" ) { $output .= "<td align='center'>$state</td>\n" ; + my $hostname = $host_obj->hostname() ; if ( $hostname eq 0 ) { $hostname = "Hostname niet gekend" ; } #print "hostname: $hostname \n" ; $output .= "<td align='center'>$hostname</td>\n" ; my $a = nslookup(host => $ip, type => "PTR"); if ( $a eq ""){ $output .= "<td align='center'>Niet in DNS</td>\n" ; + } else { $output .= "<td align='center'>$a</td>\n" ; + } my $openPort = (join ',',$host_obj->tcp_ports('open')) +."\n" ; my @ports = split ',', $openPort; $output .= "<td align='left'>"; foreach my $port (@ports) { my $svc = $host_obj->tcp_service($port); my $service = $svc->name() ; #$output .= "$port : $service </br>" ; $output .= "$port : $service </br>" ; } $output .= "</td>\n" ; my $mac = $host_obj->mac_addr() ; $output .= "<td align='center'>$mac</td>\n" ; + my $type = $host_obj->mac_vendor() ; $output .= "<td align='center'>$type</td>\n" ; + } } } $output .= "<tr>\n" ; }
In reply to NMAP Parser very slow by Noosrep
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |