9

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

2 Answers2

1

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.

EngineerCoder
  • 1,445
  • 15
  • 30
0

Apache Commons Net has a SubnetUtils class which is easy and useful for IP and Netmask calculations. You can initialize an object with valid netmask values and get SubnetInfo class to get various information.

SubnetUtils subnet = new SubnetUtils("10.12.77.1", "255.255.255.242");
SubnetInfo subnetInfo = subnet.getInfo();
jdiver
  • 2,228
  • 1
  • 19
  • 20