dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Find an IP address in a set (looking for a pro's advice)

  1. #1
    Join Date
    Oct 2003
    Posts
    215

    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?

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles