in reply to I want to be a Perl Jedi
Here's one way to easily store and edit the numbers. You could also store them in a separate file, but I like the DATA trick better. Either way, the list can easily be maintained by others who may not know about regexp or perl code:
#!/bin/nsperl use strict; my $trojanfile = "trojan.log"; ## At the top makes it easier to find i +f it is changed ## Read in all the port numbers my %number; while(<DATA>) { /^#/ and next; ## Skip lines starting with '#' /(\d+)/ and $number{$1}++; ## Hash eliminates doubles gracefully } my $findport; for (sort {$a <=> $b} keys %number) { ## Sort makes it easier to read $findport .= "$_|"; } chop $findport; ## Yes, this is chop, not chomp! open (FILEOUT, ">$trojanfile") or die "Can't open $trojanfile: $!\n"; print FILEOUT "Searched for: $findport\n"; ## Slow but succinct: (my $logfile=`date +%d%b%Y` . ".elog") =~ s/\n//; open (FWLOG, "$logfile") or die "Can't open $logfile: $!\n"; while(<FWLOG>){ print FILEOUT if (/\b(?:$findport)\b/o); ## nice call ferrency } close(FWLOG); exit; __DATA__ ## This is the list of ports ## Lines with a '#" at the start are comments ## Everything else is a port number to check for ## Even embedded comments are okay, just have the number go first 12345 12346 31337 ## Default back orifice port 8787 ## Other comments here 1823 This is a comment too, but without the nice '#' 88776
|
|---|