Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find available IP range in mysql table

I have following sql. Works fine for searching IPs. But I also would like to be able so search

select * from table 
where (INET_ATON(ip) BETWEEN INET_ATON('10.12.77.1') AND INET_ATON('10.12.77.10') )
limit 30

results is fine

10.12.77.2
10.12.77.5
10.12.77.6

how can I get available IPs like

10.12.77.1
10.12.77.3
10.12.77.4
10.12.77.7
10.12.77.8
10.12.77.9
10.12.77.10

Is it possible to do in mysql, or should I do this in Java?

Thx

like image 982
user2475153 Avatar asked May 11 '14 07:05

user2475153


1 Answers

Did you try not between :

select * from table 
where (INET_ATON(ip) NOT BETWEEN INET_ATON('10.12.77.1') AND INET_ATON('10.12.77.10') )
limit 30

By the way your query is looking 1 to 10, so why limit 30 ? It should be 10.

Regards.

like image 54
EngineerCoder Avatar answered Oct 02 '22 13:10

EngineerCoder