Noosrep has asked for the wisdom of the Perl Monks concerning the following question:
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" ; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: NMAP Parser very slow
by BrowserUk (Patriarch) on Nov 02, 2016 at 13:29 UTC | |
by Anonymous Monk on Nov 02, 2016 at 18:33 UTC | |
by Noosrep (Novice) on Nov 02, 2016 at 15:52 UTC | |
|
Re: NMAP Parser very slow (updated)
by haukex (Archbishop) on Nov 02, 2016 at 13:36 UTC | |
by Noosrep (Novice) on Nov 02, 2016 at 16:01 UTC | |
|
Re: NMAP Parser very slow
by glasswalk3r (Friar) on Nov 02, 2016 at 13:27 UTC |