#!/usr/bin/perl -w use strict; use Socket qw(inet_aton); use constant USAGE => "usage: npr.pl "; my $infilename = shift || die USAGE; my $outfilename = shift || "portreport"; die USAGE if @ARGV; my @data = do { open my $fh, "<", $infilename or die "Could not open $infilename: $!\n"; <$fh> }; die "$infilename does not appear to be a valid NessusWX Export File\n" unless $nessusdata[0] =~ m/\[NessusWX Export File\]/; my (@port, @ip); for (@data) { my @field = split /\|/; next if $field[2] or $field[0] =~ /(NessusWX|DATA)/; push @port, $_; push @ip, $result[0]; } my @uniqip = do { my %seen; grep !$seen{$_}++, @ip; }; my %longip = map { unpack("N", inet_aton $_), $_ } @uniqip; open my $fh, ">", $outfilename or die "Could not open $outfilename: $!\n"; foreach (sort { $a <=> $b } @uniqip) { my @report; for (@port) { my @field = split /\|/; next if $field[1] =~ m/general/; or not $longips{$_} =~ m/\Q$field[0]\E$/ chomp, tr/()//d for $field[1]; push @report, $field[1]; } print $fh join "|", $longips{$_}, @report; print $fh "\n"; }