Article View: alt.privacy.anon-server
Article #200905Re: mail2news - perl help required
From: Anonymous
Date: Fri, 20 Jan 2006 00:54
Date: Fri, 20 Jan 2006 00:54
52 lines
2743 bytes
2743 bytes
In article <dmukrq$pgp$1@bananasplit.info>
Zax <flee...@bananasplit.info> wrote:
> > How can I extract the IP address of the machine that passed the
> > email to me into a variable $ipaddress?
> >
> > The problem can be simplified to:
> >
> > I want to extract the first IP address (they are always enclosed
> > within []) that does not match mine, or that of any of my
> > secondary MX's (IP4 or IP6 addresses).
>
> I do it with a regex filter:
> s/^Received:.*\[(.*)\]/$1/
>
> This will strip a received header into just the ipaddress enclosed
> within the [...].
For anyone else that wanted to do the same, my problem changed
(sometimes mail would come via a secondary MX, in which case I
didn't want the first IP address). The main part is to delete
the IP addresses that are unwanted. I also gather any extra IP
addresses in the Received: header which enables some kind of
trail to stop potential abuse (obviously, messages sent through
a remailer only show as coming from the remailer, but mass
spammers don't use mixmaster as the processing time is too
costly).
Anyway, here is the code (uses CPAN module email::simple)
@received2=$mail->header("Received");
$received = join ';', @received2;
# remove our MX from Received line (change ip address to your
secondary MX)
$received=~ s/127.0.0.1//g;
$received=~ s/255.255.255.255//g;
# Get IP addresses
# Put IP addresses into ip1-5
$_ = $received;
($ip, $ip2, $ip3, $ip4, $ip5) = /\[([0-9.]+?)\]/g;
print OUTFILE "NNTP-Posting-Host: $ip\n" if $ip;
print OUTFILE "NNTP-Posting-Host2: $ip2\n" if $ip2;
print OUTFILE "NNTP-Posting-Host3: $ip3\n" if $ip3;
print OUTFILE "NNTP-Posting-Host4: $ip4\n" if $ip4;
print OUTFILE "NNTP-Posting-Host5: $ip5\n" if $ip5;
Technical Details
Message-ID:
<4208ed94418718fe9909d0211bad5b27@remailer.org.uk>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!news.amigo.co.uk!remailer.org.uk!mail2newsReferences:
<14c7789fd2c2965e8e995b6b4fd23f18@remailer.org.uk> <dmukrq$pgp$1@bananasplit.info>Show Full Headers
Complete Article Headers
Message-ID: <4208ed94418718fe9909d0211bad5b27@remailer.org.uk> Subject: Re: mail2news - perl help required Date: Fri, 20 Jan 2006 00:54:17 +0000 From: Anonymous <devnull@remailer.org.uk> References: <14c7789fd2c2965e8e995b6b4fd23f18@remailer.org.uk> <dmukrq$pgp$1@bananasplit.info> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!i2pn2.pugleaf.net!archive.newsdeef.eu!mbox2nntp-alt.privacy.anon-server.20141023.mbox.gz!number1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!news.glorb.com!news.amigo.co.uk!remailer.org.uk!mail2news Comments: This message did not originate from the Sender address above. It was remailed automatically by anonymizing remailer software. Please report problems or inappropriate use to the remailer administrator at <abuse@remailer.org.uk>. Newsgroups: alt.privacy.anon-server X-No-Archive: Yes