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.


In reply to Re: nessus port reporter by Aristotle
in thread nessus port reporter by semio

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.