procmail
[Top] [All Lists]

Re: Procmail vs perl script syntax

2006-08-15 00:41:28

On Tue, 15 Aug 2006, Brandon Enright wrote:

On Mon, 2006-08-14 at 19:42 -0500, Jack Stone wrote:
I am trying to use a procmail recipe that first runs a perl script to get
the "remote IP" of a message, but I have a syntax error in the perl script.
Got the script from SORBS.

        I'm not a perl expert but I think that if you get a message with
        Subject: Matlab ver. [9.44.300.6]  The following scripts will give
        you junk.

        You should ask your self and fine the answer in the place where
        you took the script, what is "remote IP".

Bye,
  Udi



The error is shown in the variable used for the first line of the script.

What should I do with this variable to make it right?


@msg = ;  <---THIS cause error

foreach $line ( @msg )
{
     chop $line;

     if( $line =~ /.*\[(\d+.*)\]/ )
     {
             $REMOTEIP = $1;
             last;
     }
}
print STDOUT ( $REMOTEIP );


Thanks for any tips.

Jack


I assume you want to read from STDIN.

You really don't need to make a list/array to hold each, you can loop on
the <STDIN> file handle.

Also, the regular expression you used is quite a hack and is going to
match a lot more than you want.

Give this script a try:

------------------------------------------------
#!/usr/bin/perl

use strict;
use warnings;

my $REMOTEIP;

while ( <STDIN> )
{
       chomp;
       my $line = $_;

       # This regex is *more* like an IP but still matches more
       if( $line =~ m/\[(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\]/ )
       {
               $REMOTEIP = $1;
               last;
       }
}

unless ($REMOTEIP eq '')
{
       print $REMOTEIP, "\n";
}

1;
------------------------------------------------


This may need more work to get it to your liking but should be pretty
close.  Note that this script probably isn't going to make a great
filter -- it only prints the first [ipaddress] it finds -- discarding
the rest of the input.

Brandon


-- 
Brandon Enright
Network Security Analyst
UCSD ACS/Network Operations
bmenrigh(_at_)ucsd(_dot_)edu


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail






************************************************************************************
This footnote confirms that this email message has been scanned by
PineApp Mail-SeCure for the presence of malicious code, vandals & computer 
viruses.
************************************************************************************




____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>