Re: [Exim] Wish list: isIPaddress predicate

Top Page
Delete this message
Reply to this message
Author: John Jetmore
Date:  
To: Alun
CC: Exim users list
Subject: Re: [Exim] Wish list: isIPaddress predicate
On Fri, 5 Sep 2003, Alun wrote:

> As a quicky, you could have this by jumping into perl (if compiled in):
>
> In /etc/exim/exim.pl:
>
> sub isipaddr
> {
>     return ((/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
>             && ($1 >= 0) && ($1 <= 255)
>             && ($2 >= 0) && ($2 <= 255)
>             && ($3 >= 0) && ($3 <= 255)
>             && ($4 >= 0) && ($4 <= 255)) ? "yes" : "no";
> }


This doesn't work as advertised. Change:

    return ((/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)


to:

    return (($_[0] =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)


I tested it with this:

my $t = shift;
print "$t is an ip: ", isipaddr($t), "\n";
sub isipaddr
{
    #return ((/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
    return (($_[0] =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/)
            && ($1 >= 0) && ($1 <= 255)
            && ($2 >= 0) && ($2 <= 255)
            && ($3 >= 0) && ($3 <= 255)
            && ($4 >= 0) && ($4 <= 255)) ? "yes" : "no";
}