Find an IP address in a set (looking for a pro's advice)
I am looking to to store several sets of 'IP addresses ranges' (e.g: a.b.c.d to w.x.y.z) in a table. I would then like to take a given IP address and search MySQL to find whether the IP address exist in the database.
As of now, the best approach I can think of is to
- store the IP address ranges as regular expressions in the db
- php script grabs all regexes and stores in an array
- php scripts loops through each array entry, and checks for match
Is there a better way?
if you're only dealing with ipv4, you'd be better off storing as the 4 separate octets (ie split the IP at the .) for both the low end and high end of the range. querying against that should be easier.
even if you're dealing with ipv6, you might get away with this same approach, but you need to deal with hex #'s as well.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)