m/[NessusWX Export File]/
Are you sure you want to test whether the file contains any of the characters N, e, s, u, W, X, E, x, p, o, r, t, F, i, or l? If not, you have to backslash the square brackets.
Also, this is a matter of style, but I suggest you declare your variables when you first use them. That makes it much easier to keep track of what gets used where - esp if the code is longer than this example.
Untested:
#!/usr/bin/perl -w
use strict;
use Socket qw(inet_aton);
use constant USAGE => "usage: npr.pl <NessusWX Export File>";
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";
}
Makeshifts last the longest. |