Compare range of ip addresses with start and end ip address in MySQL

Posted by Maarten on Stack Overflow See other posts from Stack Overflow or by Maarten
Published on 2010-06-15T13:11:59Z Indexed on 2010/06/15 13:12 UTC
Read the original article Hit count: 280

Filed under:
|
|

I have a MySQL table where I store IP ranges. It is setup in the way that I have the start address stored as a long, and the end address (and an id and some other data). Now I have users adding ranges by inputting a start and end ip address, and I would like to check if the new range is not already (partially) in the database.

I know I can do a between query, but that doesn't seem to work with 2 different columns, and I also cannot figure out how to pass a range to compare it. Doing it in a loop in PHP is a possibility, but would with a range of e.g. 132.0.0.0-199.0.0.0 be quite a big amount of queries..

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql