Advertisement
mightyroot

nmap report XLS summary

Aug 15th, 2012
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.42 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use Nmap::Parser;
  3. #################################################
  4. # Script usage:                                 #
  5. # nmap_xml2xls.pl /path/to/nmap_tcp_ports.xml \ #
  6. # /path/to/nmap_udp_ports.xml                   #
  7. #                                               #
  8. # then paste data to xls-file                   #
  9. #                                               #
  10. #                               (c) r3dh4t      #
  11. #################################################
  12. my $npt = new Nmap::Parser;
  13. my $npu = new Nmap::Parser;
  14. my $netblock_tcp = $ARGV[0];
  15. my $netblock_udp = $ARGV[1];
  16.  
  17. $npt->parsefile($netblock_tcp);
  18. $npu->parsefile($netblock_udp);
  19. #GETTING SCAN INFORMATION
  20. my $si_tcp = $npt->get_session();
  21. my $si_udp = $npu->get_session();
  22.  
  23. for my $host_tcp ($npt->all_hosts()){   # Get scanned hosts in network
  24.     $host_tcp->ipv4_addr();
  25.     @hst_tcp = $host_tcp->tcp_ports;            # If host is UP
  26.     if (@hst_tcp){
  27.     $ipaddr = $host_tcp->ipv4_addr();
  28.     $macaddrs = $host_tcp->mac_addr();
  29.     $macaddr = $macaddrs;
  30.       for $port ($host_tcp->tcp_ports()){               # Get host's service,ports,etc..
  31.         $service = $host_tcp->tcp_service($port);
  32.         if ( $os ne $host_tcp->os_sig){
  33.             $os = $host_tcp->os_sig;
  34.             $os_banner = $os->name.",".$os->family; #.",".$os->osgen();
  35.         } else { $os_banner = "" }
  36.         $service_banner = $port."/tcp ".$service->name." ".$service->product." ".$service->version;
  37.         $macaddr =~s/://g;
  38.         if ($macaddr==$macadd) { $macaddr = ""}
  39.         if ($ipaddr eq $ipadd) {
  40.         print ";$service_banner\n";
  41.         }else{
  42.         print "$ipaddr;PORTS;$os_banner;$macaddrs\n";
  43.         &udp_ports($ipaddr);
  44.         }
  45.         $ipadd=$ipaddr;
  46.         $macadd=$macaddr;
  47.  
  48.       }
  49.     }
  50. }
  51.  
  52. sub udp_ports($ipaddr) {
  53.      print ";UDP\n";
  54.  for my $host_udp ($npu->all_hosts()){  # Get scanned hosts in network
  55.     $host_udp->ipv4_addr();
  56.     @hst_udp = $host_udp->udp_ports;            # If host is UP
  57.     if (@hst_udp){
  58.     $ipudp = $host_udp->ipv4_addr();
  59.      if ($ipudp eq $ipaddr){
  60.       for $port ($host_udp->udp_ports()){               # Get host's service,ports,etc..
  61.         $service = $host_udp->udp_service($port);
  62.         $service_banner = $port."/udp ".$service->name." ".$service->product." ".$service->version;
  63.         print ";$service_banner;\n";
  64.       }
  65.  
  66.      }
  67.     }
  68.  }
  69.      print ";TCP\n"
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement