Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use Nmap::Parser;
- #################################################
- # Script usage: #
- # nmap_xml2xls.pl /path/to/nmap_tcp_ports.xml \ #
- # /path/to/nmap_udp_ports.xml #
- # #
- # then paste data to xls-file #
- # #
- # (c) r3dh4t #
- #################################################
- my $npt = new Nmap::Parser;
- my $npu = new Nmap::Parser;
- my $netblock_tcp = $ARGV[0];
- my $netblock_udp = $ARGV[1];
- $npt->parsefile($netblock_tcp);
- $npu->parsefile($netblock_udp);
- #GETTING SCAN INFORMATION
- my $si_tcp = $npt->get_session();
- my $si_udp = $npu->get_session();
- for my $host_tcp ($npt->all_hosts()){ # Get scanned hosts in network
- $host_tcp->ipv4_addr();
- @hst_tcp = $host_tcp->tcp_ports; # If host is UP
- if (@hst_tcp){
- $ipaddr = $host_tcp->ipv4_addr();
- $macaddrs = $host_tcp->mac_addr();
- $macaddr = $macaddrs;
- for $port ($host_tcp->tcp_ports()){ # Get host's service,ports,etc..
- $service = $host_tcp->tcp_service($port);
- if ( $os ne $host_tcp->os_sig){
- $os = $host_tcp->os_sig;
- $os_banner = $os->name.",".$os->family; #.",".$os->osgen();
- } else { $os_banner = "" }
- $service_banner = $port."/tcp ".$service->name." ".$service->product." ".$service->version;
- $macaddr =~s/://g;
- if ($macaddr==$macadd) { $macaddr = ""}
- if ($ipaddr eq $ipadd) {
- print ";$service_banner\n";
- }else{
- print "$ipaddr;PORTS;$os_banner;$macaddrs\n";
- &udp_ports($ipaddr);
- }
- $ipadd=$ipaddr;
- $macadd=$macaddr;
- }
- }
- }
- sub udp_ports($ipaddr) {
- print ";UDP\n";
- for my $host_udp ($npu->all_hosts()){ # Get scanned hosts in network
- $host_udp->ipv4_addr();
- @hst_udp = $host_udp->udp_ports; # If host is UP
- if (@hst_udp){
- $ipudp = $host_udp->ipv4_addr();
- if ($ipudp eq $ipaddr){
- for $port ($host_udp->udp_ports()){ # Get host's service,ports,etc..
- $service = $host_udp->udp_service($port);
- $service_banner = $port."/udp ".$service->name." ".$service->product." ".$service->version;
- print ";$service_banner;\n";
- }
- }
- }
- }
- print ";TCP\n"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement