www.webdeveloper.com
Results 1 to 2 of 2

Thread: how to check if ip is in ip range

  1. #1
    Join Date
    May 2010
    Posts
    136

    how to check if ip is in ip range

    I can't figure this. Can this be done alone with mysql, or there are somethings I need to do with php script.Let say I have many ip range stored in the database one of them is, 142.58.103.1 - 142.58.103.45. The table structure is like this

    Code:
        ip                                                 customer name
    142.58.103.1 - 142.58.103.45                                name1
    119.111.81.224 - 119.111.81.255                           name2
    Let say someone accessed a website and his ip is 142.58.103.12. Now with this ip, it should get name1 from customer name column as it's is in the range of 142.58.103.1 - 142.58.103.45.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,384
    I would store the upper and lower bounds as two integer fields, using MySQL's conversion functions (or PHP's ip2long()) to convert them. Then you can similarly convert any IP address of interest to an integer, and use the SQL "BETWEEN" operator to see if there is a match.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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