|
|
| laziness, impatience, and hubris | |
| PerlMonks |
Re: IP in rangeby smahesh (Pilgrim) |
| on Jan 07, 2011 at 03:27 UTC ( #880996=note: print w/ replies, xml ) | Need Help?? |
|
Hi, I solved this problem in my previous company in Java. I will present the idea here but leave the implementation to you.
A IPv4 address is just a collection of four octets and can be represented by a 32 bit integer. Just convert the start and end address of the ip range to a 32 bit integer representation. Convert the Ipv4 address to be checked also into a 32 bit number and if the number falls between the start and end numbers, it is in the range. If the address check is called lots of times for a particular range, a integer comparison will be faster than a string comparison.
For example, Mahesh
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||