Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Match a Range of IP's

by fokat (Deacon)
on Sep 30, 2004 at 23:18 UTC ( #395505=note: print w/replies, xml ) Need Help??


in reply to Match a Range of IP's

Hi there:

This is a task for NetAddr::IP...

perl -MNetAddr::IP -ne 'print "$_ match\n" if NetAddr::IP->new("192.168.1/24")->contains(NetAddr::IP->new($_))'

Best regards

-lem, but some call me fokat

Replies are listed 'Best First'.
Re^2: Match a Range of IP's
by runrig (Abbot) on Sep 30, 2004 at 23:34 UTC
    NetAddr::IP->new("192.168.1/24")->contains(NetAddr::IP->new($_))
    Except that the CIDR address you have doesn't match the OP's desired range (192.168.1.0-192.168.99.255), so he'd have to run your code up to 99 times to see if the address is in that range. Or just another way (not tested):
    use Net::CIDR::Lite; my $range = Net::CIDR::Lite->new("192.168.1.0-192.168.99.255"); while (<DATA>) { chomp; print "$_\n" if $range->find($_); }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://395505]
help
Chatterbox?
[LanX]: inspect %INC ?
[Lady_Aleena]: LanX, for every module I've written?
[huck]: Lady_Aleena see Re: pl script in webserver and/or Re: pl script in webserver for what they use
[Lady_Aleena]: Wouldn't I have to run the modules somehow to get their %INC?
[huck]: the first one works just fine from the command line but requires editing
[huck]: but neither will handle autoloads

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2017-05-27 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?