Re: [Exim] Wish list: isIPaddress predicate

Página Inicial
Delete this message
Reply to this message
Autor: John Jetmore
Data:  
Para: Alun
CC: Exim users list
Assunto: 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";
}