mercredi 16 septembre 2015

Iterating through all IP addresses in a CIDR using java

I want to know if there is any way to explode IPs of CIDR format. Along with exploding this code should take care of considering 'exclude' feature also.

To be precise, I want something that takes something like 172.21.3.128/30(Inclusion list:172.21.3.128/30) and returns

  • 172.21.3.128
  • 172.21.3.129
  • 172.21.3.130
  • 172.21.3.131

And if it has exclusion list as '172.21.3.130'(Inclusion list:172.21.3.128/30 & exclusion list:172.21.3.130) then it should return

  • 172.21.3.128
  • 172.21.3.129
  • 172.21.3.131

Currently I explode inclusion list & keep in Set and explode exclusion list & keep in set.And take the difference between two.Problem with this approach is I have to keep all exploded IPs in memory which might create problem(outofmemoryerror) if range is very big.

Aucun commentaire:

Enregistrer un commentaire