[26615] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8727 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 3 06:05:26 2005

Date: Sat, 3 Dec 2005 03:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 3 Dec 2005     Volume: 10 Number: 8727

Today's topics:
    Re: [Noob] IPC <n00b@n00b.noob>
        How to gather IP address from Recevied: headers <news@amigo.co.uk>
    Re: IO::Socket help <sisyphus1@nomail.afraid.org>
    Re: Matching escaped delimiter chars robic0
    Re: Matching escaped delimiter chars robic0
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 03 Dec 2005 10:57:37 +0100
From: noob <n00b@n00b.noob>
Subject: Re: [Noob] IPC
Message-Id: <43916bfe$0$27594$4fafbaef@reader1.news.tin.it>

Tad McClellan ha scritto:
> Perl ships with thousands of pages of documentation that is part
> of a normal install, include some Frequently Asked Questions.
> 
> You should consult those docs as a first step to finding answers.
> Likely to have already been asked (and answered), all you need to
> do is find it.
> 
> The First Place to look is in the Perl FAQs.
> 
> I assume that you know what the "P" in IPC stands for, so:
> 
>    perldoc -q process
> 
>        How do I start a process in the background?
> 
> 

Thanks


------------------------------

Date: Sat, 3 Dec 2005 10:29:37 +0000
From: David Mahon <news@amigo.co.uk>
Subject: How to gather IP address from Recevied: headers
Message-Id: <iFVsNjVROXkDFwi5@earth.amigo.co.uk>

I have a perl program which examines an email (using email::simple).

One of the headers is gathered by:

@received=$mail->header("Received");


and saved using:

print OUTFILE "Received: @received\n" if @received;


How can I extract the IP address of the machine that passed the email to 
one of my machines? My system has multiple MX records. I want the IP 
address of the machine sending the mail to one of the ones under my 
control.

In almost all of the following examples, I would be wanting 
"81.187.230.6" to be returned, as this was the outgoing smtp server for 
my test messages (except for the last one, which is a local message).


Here is an example of mail sent direct:

Received: from saturn.amigo.co.uk ([81.187.230.6]) by 
jupiter.amigo.co.uk with esmtp (Exim 4.54) id 1EiTyM-0002I1-Lr for 
test@testdomain.com; Sat, 03 Dec 2005 09:46:26 +0000 from 
earth.amigo.co.uk ( [81.187.230.3]) by amigo.co.uk with ESMTP 
(Mailtraq/2.7.1.1862) id AMGC2B212AD8 for test@testdomain.com; Sat, 03 
Dec 2005 09:46:21 -0000


Here is an example by received from a secondary MX:

Received: from b.hopeless.aaisp.net.uk ([81.187.81.12] 
ident=[U2FsdGVkX199l1baK8tXe/WvO+LC4Iu53KbUETkAmKk=]) by 
jupiter.amigo.co.uk with esmtp (Exim 4.54) id 1EiU4f-0002Md-MH for 
test@jupiter.amigo.co.uk; Sat, 03 Dec 2005 09:52:57 +0000 from 
saturn.amigo.co.uk ([81.187.230.6]) by B.hopeless.aaisp.net.uk 
([81.187.81.12]) with AAISP icebox mailer (build Nov 15 2005 17:36:31) 
for test@testdomain.com; Sat, 03 Dec 2005 09:52:57 +0000 from 
earth.amigo.co.uk ( [81.187.230.3]) by amigo.co.uk with ESMTP 
(Mailtraq/2.7.1.1862) id AMGC2B212AE5 for test@testdomain.com; Sat, 03 
Dec 2005 09:52:42 -0000


Here is an example received from my tertiary MX:

Received: from regardless.aaisp.net.uk ([81.187.30.42] 
helo=tertiary-mx.co.uk 
ident=[U2FsdGVkX185NJTsN0/QIxJfejckIpUPKbUwtfqmKjI=]) by 
jupiter.amigo.co.uk with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) 
(Exim 4.54) id 1EiU3S-0002L7-A1 for test@testdomain.com; Sat, 03 Dec 
2005 09:51:42 +0000 from saturn.amigo.co.uk ([81.187.230.6]) by 
tertiary-mx.co.uk with esmtp (Exim 4.43) id 1EiU3Q-0005ES-D4 for 
test@testdomain.com; Sat, 03 Dec 2005 09:51:40 +0000 from 
earth.amigo.co.uk ( [81.187.230.3]) by amigo.co.uk with ESMTP 
(Mailtraq/2.7.1.1862) id AMGC2B212ADD for test@testdomain.com; Sat, 03 
Dec 2005 09:49:27 -0000


(it's even possible that the mail could go tertiary -> secondary -> 
primary MX)

Received: from b.hopeless.aaisp.net.uk ([81.187.81.12] 
ident=[U2FsdGVkX19ybkaIvD81d8AAmAYb2rGz2ZDrfye9M/0=]) by 
jupiter.amigo.co.uk with esmtp (Exim 4.54) id 1EiUFm-0002Uw-By for 
test@jupiter.amigo.co.uk; Sat, 03 Dec 2005 10:04:26 +0000 from 
regardless.aaisp.net.uk ([2001:8B0:0:30::51BB:1E2A] 
helo=tertiary-mx.co.uk) by B.hopeless.aaisp.net.uk 
([2001:8B0:0:81::51BB:510C]) with AAISP icebox mailer (build Nov 15 2005 
17:36:31) for test@testdomain.com; Sat, 03 Dec 2005 10:04:25 +0000 from 
saturn.amigo.co.uk ([81.187.230.6]) by tertiary-mx.co.uk with esmtp 
(Exim 4.43) id 1EiUFl-0005jk-Ms for test@testdomain.com; Sat, 03 Dec 
2005 10:04:25 +0000 from earth.amigo.co.uk ( [81.187.230.3]) by 
amigo.co.uk with ESMTP (Mailtraq/2.7.1.1862) id AMGC2B222AF8 for 
test@testdomain.com; Sat, 03 Dec 2005 10:04:08 -0000


The final (I hope) alternative is that the mail is sent locally, and 
therefore should be recognised as 127.0.0.1

Received: from user1 by jupiter.amigo.co.uk with local (Exim 4.54) id 
1EfkYM-0006qz-Oo for test@testdomain.com; Fri, 25 Nov 2005 20:52:18 
+0000


I suppose I want the first IP address (address enclosed in []) that 
isn't an IP address of my MX hosts. Made slightly more complex by the 
fact that some use IP6 addresses on occasion.

So, I want the first IP address enclosed in [] that is NOT

81.187.81.12 or 2001:8B0:0:81::51BB:510C
81.187.30.42 or 2001:8B0:0:30::51BB:1E2A

or 127.0.0.1 if there are none.

Help please - how do I do this?



-- 
David Mahon


------------------------------

Date: Sat, 3 Dec 2005 19:37:33 +1100
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: IO::Socket help
Message-Id: <439159a4$0$6195$afc38c87@news.optusnet.com.au>


"Vespasian" <ves@ves.net>
 .
 .
> while the following does not i.e. it dies at the die statement,
>

use warnings;
use strict;
use IO::Socket;

> my $port = 9850;
> my $proto = getprotobyname('tcp');
>
>
> my $sock = new IO::Socket::INET(
>    LocalHost => 'localhost',
> LocalPort => 9850,
> Proto => 'tcp',
> Listen => SOMAXCONN,
> Type => SOCK_STREAM,
> Reuse => 1);
>
> $sock or die "no socket :$!";
>
>
> print "SERVER started on port $port\n";
>
> # accepting a connection
> my $client_sock = $sock->accept();
>

Don't know what the problem is. Works fine for me - prints "SERVER started
on port 9850" and just sits there waiting for a connection.
Don't forget to 'use warnings;'.

Cheers,
Rob




------------------------------

Date: Sat, 03 Dec 2005 01:10:30 -0800
From: robic0
Subject: Re: Matching escaped delimiter chars
Message-Id: <e0o2p15olvh6f4ftlk9e7sob98mofedatr@4ax.com>

On Tue, 29 Nov 2005 00:02:19 -0800, robic0 wrote:

>On Mon, 28 Nov 2005 21:21:09 +0100, Witold Rugowski
><witold.rugowski@hp.com> wrote:
>
>>Hi!
>>I want to match with regexp substring, which is delimited by, let's say ". It is trivial, but I don't know how to match escaped quotes with \. OK, example will be better ;-))
>>
>>Let's take string such:
>>AAAAAAA "blah blah \" blah blah" BBBBBB
>>
>>How to match all what is in between quotes, not counting escaped quote. In this case it should match to:
>>blah blah \" blah blah
>>
>>How it can be done????
>>
>>Best regards,
>>Witold Rugowski
>
>my @regx_esc_codes = ( "\\", '/', '(', ')', '[', ']', '?', '|',
>     '+', '.', '*', '$', '^', '{', '}', '@' );
>
>my $funky_string = 'AAAAAAA "blah blah \" blah blah" BBBBBB';
>my $match_string = 'your_logic_here';
>for (@regx_esc_codes)
>{
>	my $tc = $_;
>	 # code template for regex
>	my $xx = "\$match_string =~ s/\\$tc/\\\\\\$tc/g;";
>	eval $xx;
>	#print "$xx\n";
>}
>
>## match should be ready now,
>## be sure to trap regex violations
>
>$fnd = 0;
># -- #
>my $ctmpl = "if (\$funky_string =~ /$match_string/ {\$fnd = 1;}";
>eval $ctmpl;
># -- #
>
>if ($@) {
>	## Check the $ctmpl, get the control code, log this error as a
>code issue.
>	## This shouldn't happen ... the compiler will show the escape
>char, add
>	## the char to "@regx_esc_codes", now its fixed!
>	$@ =~ s/^[\x20\n\t]+//; $@ =~ s/[\x20\n\t]+$//;
>	print $@,"\n";
>	exit;
>}
>
>Note - I may be wrong in this context, its been a while
>
Oh yeah, this is how its done et all. This is what works when
qr// doesen't. Incase you don't think it works. Consider that
this puppy will handle any variable you can read in from 
unknown string content.
Now how much is that worth? Where's the regulars now?
Bunch of blow hard puffs....


------------------------------

Date: Sat, 03 Dec 2005 01:16:37 -0800
From: robic0
Subject: Re: Matching escaped delimiter chars
Message-Id: <dfo2p15cltl2o7b1pfbjaekdofra45rhur@4ax.com>

On Sat, 03 Dec 2005 01:10:30 -0800, robic0 wrote:

>On Tue, 29 Nov 2005 00:02:19 -0800, robic0 wrote:
>
>>On Mon, 28 Nov 2005 21:21:09 +0100, Witold Rugowski
>><witold.rugowski@hp.com> wrote:
>>
>>>Hi!
>>>I want to match with regexp substring, which is delimited by, let's say ". It is trivial, but I don't know how to match escaped quotes with \. OK, example will be better ;-))
>>>
>>>Let's take string such:
>>>AAAAAAA "blah blah \" blah blah" BBBBBB
>>>
>>>How to match all what is in between quotes, not counting escaped quote. In this case it should match to:
>>>blah blah \" blah blah
>>>
>>>How it can be done????
>>>
>>>Best regards,
>>>Witold Rugowski
>>
>>my @regx_esc_codes = ( "\\", '/', '(', ')', '[', ']', '?', '|',
>>     '+', '.', '*', '$', '^', '{', '}', '@' );
>>
>>my $funky_string = 'AAAAAAA "blah blah \" blah blah" BBBBBB';
>>my $match_string = 'your_logic_here';
>>for (@regx_esc_codes)
>>{
>>	my $tc = $_;
>>	 # code template for regex
>>	my $xx = "\$match_string =~ s/\\$tc/\\\\\\$tc/g;";
>>	eval $xx;
>>	#print "$xx\n";
>>}
>>
>>## match should be ready now,
>>## be sure to trap regex violations
>>
>>$fnd = 0;
>># -- #
>>my $ctmpl = "if (\$funky_string =~ /$match_string/ {\$fnd = 1;}";
>>eval $ctmpl;
>># -- #
>>
>>if ($@) {
>>	## Check the $ctmpl, get the control code, log this error as a
>>code issue.
>>	## This shouldn't happen ... the compiler will show the escape
>>char, add
>>	## the char to "@regx_esc_codes", now its fixed!
>>	$@ =~ s/^[\x20\n\t]+//; $@ =~ s/[\x20\n\t]+$//;
>>	print $@,"\n";
>>	exit;
>>}
>>
>>Note - I may be wrong in this context, its been a while
>>
>Oh yeah, this is how its done et all. This is what works when
>qr// doesen't. Incase you don't think it works. Consider that
>this puppy will handle any variable you can read in from 
>unknown string content.
>Now how much is that worth? Where's the regulars now?
>Bunch of blow hard puffs....

Incase you don't understand, "your_logic_here" could be a 
unknown, variable subset string of that which you are looking for.
I believe I could write a book on it.


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8727
***************************************


home help back first fref pref prev next nref lref last post