Re: [ILUG] perl regexp query

From: Eoin Kelly (kellyep at domain joy.ucc.ie)
Date: Mon 23 Sep 2002 - 13:33:03 IST


Ahem, that should of course be:

sub scanaddr ($) {
    my $s = $_[0];
    my at domain paddrs; # Packed IP addresses.
    my at domain addrs; # ASCII addresses.
    my $junk;
    my at domain return;

    if ($s =~ m/i(pop2|pop3|map)d\[[0-9]+\]: (Login|Authenticated) user=/) {

        $s =~ /.*host=(\S+)\s*(\S*).*/;
        my($try1,$try2) = ($1,$2);
        if ( $try1 =~ /^\[(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})\]$/ ) {
                # $1 contains the IP address now
                ($junk, $junk, $junk, $junk, at domain paddrs) = gethostbyaddr( $1, AF_INET );
        }
        elsif($try2 =~ /^\[(\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3})\]$/ ) {
                # $1 contains the IP address now
                ($junk, $junk, $junk, $junk, at domain paddrs) = gethostbyaddr( $1, AF_INET );
        }
        else {
                warn "Failed to parse IP address from '$s'";
        }

        while ( at domain paddrs) {
            push( at domain addrs, join('.', unpack('C4', shift( at domain paddrs))));
        }
        return at domain addrs;
    }
    return ();
}

/Eoin/



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:19:00 GMT