Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

(MeowChow) Re: Check IP with support for CIDR

by MeowChow (Vicar)
on Apr 12, 2002 at 01:24 UTC ( #158459=note: print w/ replies, xml ) Need Help??


in reply to Check IP with support for CIDR

You can simplify the CIDR mask check:

return unpack ('N', pack ('C4', split /\./, $i) ^ pack ('C4', split /\ +./, $1)) >> 32 - $2;
   MeowChow                                   
               s aamecha.s a..a\u$&owag.print


Comment on (MeowChow) Re: Check IP with support for CIDR
Download Code
Re: (MeowChow) Re: Check IP with support for CIDR
by xaphod (Monk) on Apr 12, 2002 at 08:06 UTC
    Could not get that to work. However, it did make me think and hence this:
    return ( (unpack('N',pack('C4',split(/\./,$i))) ^ unpack('N',pack('C4' +,split(/\./,$1)))) >> (32-$2) ) == 0;
    --
    TTFN, FNORD
      My bad, I forgot to negate the result:
      return not unpack ('N', pack ('C4', split /\./, $i) ^ pack ('C4', spli +t /\./, $1)) >> 32 - $2;
         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
        That works. So I guess you win this round of Golf.
        --
        TTFN, FNORD

        xaphod

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://158459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (16)
As of 2015-07-07 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (90 votes), past polls