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


I have a MySQL table where I store the IP category. This is the setup in the manner in which I have a starting address, and the last address (and an ID and some other data) that have been started as a long time. Now I have been adding limitations by introducing end and end IP addresses to users, and I would like to check whether the new range is not already (partially) in the database.

I know what I can do in the query, but it does not seem to work with 2 different columns, and I also can not understand that to compare it How to cross a border It's a possibility to do this in a loop in PHP, but it will be a huge amount of 132.0.0.0-199.0.0.0 queries with a wide range.

When you say that you have it accumulated as a long Addressed, I'm assuming that you mean that you have stored them (like) 10.1.2.3 will be stored as 0x0a010203. In that case, to find out if an address already exists, you can do this:

  SELECT ... ipranges WHERE ( & gt; ; = Startaddr) and (& lt; NEWADDR & gt; & lt; = endaddr)  

And then if you get back any rows, the address is already in the table. (Definitely replace & lt; NEWADDR & gt; with the new address!)

To check overlapping rows, this is just a bit more complicated:

  select ... where not from iprongs ((& lt; nudendrade & gt; & lt; startaddr) or (& lt; NEWSTARTADDR & gt; & gt; ender))  

This means that the new category does not overlap the old range, provided it starts after that, or ends before it.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -