#!perlenv -w use strict; my ( $port, $uniqip, $longip ); my ( @nessusdata, @ports, @ips, @uniqip, @splitip, @rearranged ); my %longips; my $nessusdata = $ARGV[0]; my $portreport = "portreport"; my $num = 256; my $count = 0; if ( $#ARGV < 0 ) { print "usage: npr.pl "; exit; } open( NESSUSDATA, "< $nessusdata" ) || die "Could not open file: $! \n"; @nessusdata = ; close(NESSUSDATA); open( PORTREPORT, "> $portreport" ) || die "Could not open file: $! \n"; if ( $nessusdata[0] !~ m/[NessusWX Export File]/ ) { print "File $ARGV[0] does not appear to be a valid NessusWX Export File\n"; exit 0; } foreach $nessusdata (@nessusdata) { my @result = split ( /\|/, $nessusdata ); if ( $result[0] =~ /(NessusWX|DATA)/ ) { next; } elsif ( !$result[2] ) { push @ports, $nessusdata; push @ips, $result[0]; } } @uniqip = keys %{ { @ips, reverse @ips } }; foreach $uniqip (@uniqip) { @splitip = split ( /\./, $uniqip ); $longip = ( $splitip[0] * ( $num * $num * $num ) ) + ( $splitip[1] * ( $num * $num ) ) + ( $splitip[2] * $num ) + ( $splitip[3] ); $longips{$longip} = $uniqip; } @rearranged = sort { $a <=> $b } keys %longips; foreach (@rearranged) { if ( $count == 0 ) { print PORTREPORT $longips{$_}, "|"; } else { print PORTREPORT "\n", $longips{$_}, "|"; } foreach $port (@ports) { my @result = split ( /\|/, $port ); if ( $result[1] =~ m/general/ ) { next; } elsif ( $longips{$_} =~ m/$result[0]$/ ) { $result[1] =~ s/(\(|\))//g; chomp $result[1]; print PORTREPORT $result[1], "|"; } } $count = 1; } close(PORTREPORT);