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.
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